Locate Service: Locate Device API

This api service allows you to get exact location based on coordinates.

Request Body: JSON

{
  "service": "locate-device",
  "payload": {
      "longitude": 101.1234,
      "latitude": 102.1234
  }
}

Request Body Definition

  • service - This defines the service that we want to use
  • payload - Information needed in order for the service to process the request
  • payload.longitude - This is the longitude in the coordinate. This should be type float
  • payload.latitude - This is the latitude in the coordinate. This should be type float

Sample Javascript code to get coordinates using the browser's api

navigator.geolocation.getCurrentPosition((position) => { 
  console.log('latitude', position.coords.latitude); 
  console.log('longitude', position.coords.longitude); 
});

Sample Response

If your request is successful, you will receive the following response where you get the result and the credits you have left after making the request, with a status code of 200.

{
  "result": {
    "address": "<THE FULL ADDRESS>",
    "municipality": "Ho Chi Minh",
    "neighborhood": "Phuong Tan Phu",
    "postal_code": "72908",
    "region": "Ho Chi Minh City",
    "country": "VNM",
    "search_longitude": 101.1234,
    "search_latitude": 102.1234,
  },
  "remaining_credits": 92
}

If your request is not successful, you will receive a message from the json response describing the error. Possible errors may be due to:

  • Invalid API token with status code 401
  • Invalid service name with status code of 422
  • Not enough credits with status code of 422
  • Invalid payload with status code of 422

Response Data Definition

  • result - A dictionary containing the details of the location. For the country, it uses ISO 3166 codes. Please refer to this for the different country codes.
  • remaining_credits - The remaining locate credits after calling the api service.