Location verification
The location verification feature allows you to check if a device is at a given location or not at a given moment. Network as Code sends a location retrieval request to the Network Operator, which will then tell you whether the device is within the circle you defined.
Think of the following scenario: A bank wants to check if an account holder's device is close to the ATM or even the bank branch where a transaction is about to take place. For security or authorization purposes, for example, they may wish to use the location feature.
NOTE: Querying a device's location might have serious privacy implications. So, it should be done carefully, and strict authorization may be needed.
Get the location of the device
To verify a location of a specific device, you can do it like so:
import network_as_code as nac
# We initialize the client object with your application key
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>"
)
# Create a device object for the mobile device we want to use
my_device = client.devices.get(
# The phone number does not accept spaces or parentheses
phone_number="+36721601234567"
)
# For estimations, use the `verify_location()` method
# with the geo-coordinates and maximum age in seconds.
# If the amount in seconds is not given, the default will be 60 seconds.
result = my_device.verify_location(
longitude=60.252,
latitude=25.227,
radius=10_000,
max_age=3600
)
print(result.result_type) # "TRUE", "FALSE", "PARTIAL" or "UNKNOWN" .Location verification parameters
Here are all the parameters for location estimations and a more detailed description of what they should contain:
| Parameter | Type | Description | Mandatory or Optional |
|---|---|---|---|
latitude | integer/float | Specifies the north–south position of the queried location. | Mandatory |
longitude | integer/float | Specifies the east-west position of the queried location. | Mandatory |
radius | integer/float | Specifies the accuracy of the queried area in meters. | Mandatory |
max_age | integer | Specifies the limit of how old the location data is allowed to be. If not given, default is 60 seconds. | Optional |
Accuracy of the location query
The location data might be more accurate in areas with a dense concentration of base stations, so verifying location in more sparse or remote areas might require a larger radius.
It's also good to know the accuracy of this feature is on Cell ID level and a brief loss of connection will not affect the service, which is provided promptly upon each request.
Response parameters
| Parameter | Type | Description |
|---|---|---|
result_type | string | Indicates whether a device is within the circle defined by its center location and radius. |
match_rate | integer | In case of PARTIAL, the response includes the match_rate, which indicates the likelihood of the match. |
last_location_time | datetime | Timezone-aware timestamp of the last location information. Will not be provided in case of UNKNOWN. |
Response result types
| Result | Type | Description |
|---|---|---|
TRUE | string | If the device's location is entirely within the area you requested. |
FALSE | string | The device's location falls outside the area you requested. |
PARTIAL | string | The device's location intersects with the requested area. In this case, match rate is included. |
UNKNOWN | string | If the location information is older than the one you defined in seconds. |
Remember that the geo-spatial coordinates here work on Earth only. If the radius is larger than half of Earth's circumference, it should be enough to tell if the device is in our home planet.
Simulated device location scenarios
The Network as Code simulators have been configured to provide specific device location results for specific simulated devices based on their device identifier. This will be helpful in testing your code against the different responses, including possible errors, by simply substituting the device identifier in your code.
The device identifiers and their responses can be found in the following table:
| Device identifier type | Device identifier | HTTP status code | HTTP status code description | Response description |
|---|---|---|---|---|
| Phone Number | +99999991000 | 200 | Success | Device is not in the given area |
| Phone Number | +99999991001 | 200 | Success | Device is in the given area |
| Phone Number | +99999991002 | 200 | Success | Device is partially within the area |
| Phone Number | +99999991003 | 200 | Success | Device location is unknown |
| Phone Number | +99999990400 | 400 | Bad Request | |
| Phone Number | +99999990404 | 404 | Not found | |
| Phone Number | +99999990422 | 422 | Unprocessable Entity | |
| Phone Number | +99999990500 | 500 | Internal Server Error | |
| Phone Number | +99999990502 | 502 | Bad Gateway | |
| Phone Number | +99999990503 | 503 | Service Unavailable | |
| Phone Number | +99999990504 | 504 | Gateway Timeout |
Last updated January 22, 2026