NAV Navbar
Logo
shell php python javascript

LocationIQ

Geocoding

Geocoding is the process of converting addresses (like a street address) into geographic coordinates (like latitude and longitude), which you can use to place markers on a map, or position the map.

<?php

$curl = curl_init('https://unwiredlabs.com/v2/search.php?token=YOUR_API_TOKEN&q=SEARCH_STRING');

curl_setopt_array($curl, array(
  CURLOPT_RETURNTRANSFER    =>  true,
  CURLOPT_FOLLOWLOCATION    =>  true,
  CURLOPT_MAXREDIRS         =>  10,
  CURLOPT_TIMEOUT           =>  30,
  CURLOPT_CUSTOMREQUEST     =>  'GET',
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo 'cURL Error #:' . $err;
} else {
  echo $response;
}
import requests

url = "https://unwiredlabs.com/v2/search.php"

data = {
    'token': 'YOUR_API_TOKEN',
    'q': 'SEARCH_STRING'
}

response = requests.get(url, params=data)

print(response.text)
curl --request GET \
  --url 'https://unwiredlabs.com/v2/search.php?token=YOUR_API_TOKEN&q=SEARCH_STRING'
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://unwiredlabs.com/v2/search.php?token=YOUR_API_TOKEN&q=SEARCH_STRING",
  "method": "GET"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

The above command returns JSON structured like this:

{
  "status": "ok",
  "balance": 5000,
  "address": [{
    "lat": "40.6892474",
    "lon": "-74.0445404280149",
    "display_name": "Statue of Liberty, Hudson River Waterfront Walkway, Jersey City, Hudson County, New Jersey, 10004, United States of America",
    "road": "Hudson River Waterfront Walkway",
    "county" : "Hudson County",
    "city": "Jersey City",
    "state": "New Jersey",
    "country": "United States of America",
    "country_code": "US",
    "postal_code": 10004
  }, {
    "lat": "41.3438648",
    "lon": "-86.3111653",
    "display_name": "Statue of Liberty, Rue Guynemer, Odéon, 6e, Paris, Île-de-France, 75006, France",
    "road": "Rue Guynemer",
    "city": "Île-de-France",
    "state": "Paris",
    "country":"France",
    "country_code" : "FR",
    "postal_code": 75006
  }]
}

HTTP Request

GET https://unwiredlabs.com/v2/search.php?token=YOUR_API_TOKEN&q=SEARCH_STRING

Query Parameters

Name Description Required
token Authentication Token Yes
q Address which we want to search for Yes
accept-language Preferred language order for showing search results. Read more. Optional
limit Integer value to limit the number of returned results Optional
countrycodes Limit search to a list of countries. Read more. Optional
viewbox The preferred area to find search results. (left, right, top, bottom) Optional

Response

Name Description
status ok on success; error on error
balance Balance left in the account
address Array of Address objects found for the search query. Read more

Reverse Geocoding

Reverse geocoding is the process of converting geographic coordinates into a human-readable address.

<?php

$curl = curl_init('https://unwiredlabs.com/v2/reverse.php?token=YOUR_API_TOKEN&lat=LATITUDE&lon=LONGITUDE');

curl_setopt_array($curl, array(
  CURLOPT_RETURNTRANSFER    =>  true,
  CURLOPT_FOLLOWLOCATION    =>  true,
  CURLOPT_MAXREDIRS         =>  10,
  CURLOPT_TIMEOUT           =>  30,
  CURLOPT_CUSTOMREQUEST     =>  'GET',
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import requests

url = "https://unwiredlabs.com/v2/search.php"

data = {
    'token': 'YOUR_API_TOKEN',
    'lat': 'LATITUDE',
    'lon': 'LONGITUDE'
}

response = requests.get(url, params=data)

print(response.text)
curl --request GET \
  --url 'https://unwiredlabs.com/v2/reverse.php?token=YOUR_API_TOKEN&lat=LATITUDE&lon=LONGITUDE'
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://unwiredlabs.com/v2/reverse.php?token=YOUR_API_TOKEN&lat=LATITUDE&lon=LONGITUDE",
  "method": "GET"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

The above command returns JSON structured like this:

{
  "status": "ok",
  "balance": 5000,
  "address": {
    "display_name": "Southpark Lane, Littleton, Arapahoe County, Colorado, 80120, United States of America",
    "road": "Southpark Lane",
    "county": "Arapahoe County",
    "city": "Denver-Aurora-Lakewood",
    "state": "Colorado",
    "country": "United States of America",
    "country_code" : "US",
    "postal_code": 80120
  }
}

HTTP Request

GET https://unwiredlabs.com/v2/search.php?token=YOUR_API_TOKEN&lat=LATITUDE&lon=LONGITUDE

Query Parameters

Name Description Required
token Authentication token Yes
lat Latitude of the location address Yes
lon Longitude of the location address Yes
zoom Zoom value lies between 0-18. Level of detail required where 0 is country and 18 is house/building Optional
accept-language Preferred language order for showing search results. Read more. Optional

Response

Name Description
status ok on success; error on error
balance Balance left in the account
address Address object found for the search query. Read more.

Timezone

The Unwired Labs TimeZone API provides time offset data for locations on the surface of the earth.

<?php

$curl = curl_init('https://unwiredlabs.com/v2/timezone.php?token=YOUR_API_TOKEN&lat=LATITUDE&lon=LONGITUDE');

curl_setopt_array($curl, array(
  CURLOPT_RETURNTRANSFER    =>  true,
  CURLOPT_FOLLOWLOCATION    =>  true,
  CURLOPT_MAXREDIRS         =>  10,
  CURLOPT_TIMEOUT           =>  30,
  CURLOPT_CUSTOMREQUEST     =>  'GET',
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo 'cURL Error #:' . $err;
} else {
  echo $response;
}
import requests

url = "https://unwiredlabs.com/v2/timezone.php"

data = {
    'token': 'YOUR_API_TOKEN',
    'lat': 'LATITUDE',
    'lon': 'LONGITUDE'
}

response = requests.get(url, params=data)

print(response.text)
curl --request GET \
  --url 'https://unwiredlabs.com/v2/timezone.php?token=YOUR_API_TOKEN&lat=LATITUDE&lon=LONGITUDE'
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://unwiredlabs.com/v2/timezone.php?token=YOUR_API_TOKEN&lat=LATITUDE&lon=LONGITUDE",
  "method": "GET"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

The above command returns JSON structured like this:

{
  "status": "ok",
  "balance": 5000,
  "timezone": {
    "name": "Asia/Kolkata",
    "now_in_dst": 0,
    "offset_sec": 19800,
    "short_name": "IST"
  }
}

HTTP Request

GET https://unwiredlabs.com/v2/timezone.php?token=YOUR_API_TOKEN&lat=LATITUDE&lon=LONGITUDE

Query Parameters

Name Description Required
token Authentication token Yes
lat Latitude of the location Yes
lon Longitude of the location Yes

Response

Name Description
status ok on success; error on error
balance Balance left in the account
timezone Timezone object found for the location. Read more

Timezone Response

Name Description
short_name Short name of the Timezone
offset_sec The offset from UTC (in seconds) for the given location. Considers DST savings.
now_in_dst Represents whether the zone currently observing DST or not
name Timezone name of the Location

Notes

Address

Name Description
display_name Matched Address name for the given location
house_number House Number
road Road Name
neighbourhood Neighbourhood
suburb Suburb
county County name (normalized form of county, state_district)
city City name (normalized form of city, town, village, hamlet)
country Country name
country_code Country code
postal_code Postal code

Accept Language

Preferred language order for showing search results, overrides the value specified in the Accept-Language HTTP header. Either uses standard rfc2616 accept-language string or a simple comma separated list of language codes.

Country Codes

Limit search results to a specific country (or a list of countries). Should be the ISO 3166-1alpha2 code. Here is a sample:

Country code Country
de Germany
gb United Kingdom
us United States of America

Errors

{
  "status": "error",
  "message": "Error message"
}

When certain types of errors are encountered, LocationIQ API responds the following error messages:

Error Message Description
NO_TOKEN The request does not contain the user’s token
INVALID_TOKEN The user’s token set is not valid
INACTIVE_TOKEN The user’s token is not active
INVALID_INPUT The request does not contain the required input in the specified format
DAILY_LIMIT The user has reached the daily limit allocated
NO_RESULTS The request is valid and we could not find a proper result
NO_MATCHES_FOUND We are unable to process your request
UNKNOWN_ERROR Due to an unknown error, we are unable to serve your request

Maps

LocationIQ’s Map tiles - including Streets and Satellite imagery - are rendered by the popular and open-source LeafletJS library. Our documentation includes a quick-start guide which will get you started on basics, including setting up a LocationIQ Map, working with markers, polylines and popups, and dealing with events. For further reading, we recommend the comprehensive LeafletJS documentation.

Quick start guide

Before writing any code for the map, you need to do the following preparation steps on your page:

Now you’re ready to initialize the map and do some stuff with it.

Setting up the map

Markers, circles and polygons

Working with popups

Dealing with events

Further reading

LocationIQ’s Maps are rendered by the popular LeafletJS library. For more advanced configurations and options, please refer to Leaflet’s documentation.