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 deviceheader link

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 parametersheader link

Here are all the parameters for location estimations and a more detailed description of what they should contain:

ParameterTypeDescriptionMandatory or Optional
latitudeinteger/floatSpecifies the north–south position of the queried location.Mandatory
longitudeinteger/floatSpecifies the east-west position of the queried location.Mandatory
radiusinteger/floatSpecifies the accuracy of the queried area in meters.Mandatory
max_ageintegerSpecifies the limit of how old the location data is allowed to be. If not given, default is 60 seconds.Optional

Accuracy of the location queryheader link

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 parametersheader link

ParameterTypeDescription
result_typestringIndicates whether a device is within the circle defined by its center location and radius.
match_rateintegerIn case of PARTIAL, the response includes the match_rate, which indicates the likelihood of the match.
last_location_timedatetimeTimezone-aware timestamp of the last location information. Will not be provided in case of UNKNOWN.

Response result typesheader link

ResultTypeDescription
TRUEstringIf the device's location is entirely within the area you requested.
FALSEstringThe device's location falls outside the area you requested.
PARTIALstringThe device's location intersects with the requested area. In this case, match rate is included.
UNKNOWNstringIf 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 scenariosheader link

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 typeDevice identifierHTTP status codeHTTP status code descriptionResponse description
Phone Number+99999991000200SuccessDevice is not in the given area
Phone Number+99999991001200SuccessDevice is in the given area
Phone Number+99999991002200SuccessDevice is partially within the area
Phone Number+99999991003200SuccessDevice location is unknown
Phone Number+99999990400400Bad Request
Phone Number+99999990404404Not found
Phone Number+99999990422422Unprocessable Entity
Phone Number+99999990500500Internal Server Error
Phone Number+99999990502502Bad Gateway
Phone Number+99999990503503Service Unavailable
Phone Number+99999990504504Gateway Timeout

Last updated January 22, 2026