Location retrieval
This feature allows you to get the geographic coordinates of a device and exhibit them on the screen. You will also need to specify a certain amount of time or a maximum time limit for the location information you receive. This way, your device's location will always be up to date!
NOTE: Querying a device's location might have serious privacy implications. So, it should be done carefully, and strict authorization may be needed.
Retrieving and displaying a device's location
Retrieving the location of a device can be fairly simple.
Assuming a device was already created in this previous step,
a location object, as the ones below,
can be instantiated from the fields for longitude and latitude.
You can use the following code snippets to exhibit a device's geographic coordinates:
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"
)
# Specify the maximum amount of time accepted
# to get location information, it's a mandatory parameter.
# If the amount in seconds is not given, the default will be 60 seconds.
location = my_device.location(max_age=3600)
# The location object contains fields for longitude, latitude and radius
print(location)Location retrieval parameters
The only parameter to retrieve a location is the Maximum Age.
You should inform the integer value expected in seconds.
Let's suppose you don't want to retrieve information older than 1 hour.
Then, defining the value in seconds, for example 3600,
will check if the device was at the location informed at most 1 hour ago.
| Parameters | Type | Description | Mandatory or Optional |
|---|---|---|---|
max_age | integer | The maximum age accepted for the location information request in seconds. If not given, default is 60 seconds. | Optional |
Remember: The location data does not update automatically. So, to get an up-to-date device location, just fetch it again:
location = my_device.location(max_age=3600)
print(location)Accuracy of the location query
The location data might be more accurate in areas
with a dense concentration of base stations, but less accurate in more sparse or remote areas.
Also, if the location information is older than the one you defined in seconds,
then the output of request will be UNKNOWN.
Response parameters
| Parameters | Type | Description |
|---|---|---|
longitude | integer/float | Indicates the north–south position of the location. |
latitude | integer/float | Indicates the east-west position of the location. |
radius | integer | Indicates the accuracy of the queried area in meters. |
Last updated December 19, 2025