Convert Coordinates To Addresses
You can use the Reverse Geocoding API to convert coordinates to street addresses
Do You Have Your Access Token?
Before you proceed, ensure you have your access token at hand. Can't find your token? No worries — our guide will assist you in either creating a new one or finding your existing token.
Step 1: Gather Coordinates
Start with your latitude and longitude coordinates, like "40.7128, -74.0060" for Broadway, New York City.
Step 2: API Request
Craft a simple API request using LocationIQ's Reverse geocoding API endpoint.
https://us1.locationiq.com/v1/reverse?key=YOUR_ACCESS_TOKEN&lat=40.7128&lon=-74.0060&format=json
- https://us1.locationiq.com/v1/reverse: This is the base URL of the LocationIQ API for reverse geocoding.
key=
: This parameter specifies your access token. If you don't have one, follow the guide here to get your access token.lat=
40.7128: This parameter specifies the latitude of the location you want to reverse geocode.lon=
-74.0060: This parameter specifies the longitude of the location you want to reverse geocode.format=
json: This parameter specifies the desired output format for the response. In this case, you're requesting the response to be in JSON format, which is a common data format used for exchanging information between a server and a client.
Step 3: Parse Output
Parse the API output and capture the address elements you need. That's it!
{
"place_id": "332690606332",
"osm_type": "way",
"osm_id": "575213527",
"licence": "https:\/\/locationiq.com\/attribution",
"lat": "40.712641",
"lon": "-74.006087",
"display_name": "260, Broadway, Civic Center, New York, New York County, New York, 10007, USA",
"boundingbox": ["40.712641", "40.712641", "-74.006087", "-74.006087"],
"importance": 0.2,
"address": {
"house_number": "260",
"road": "Broadway",
"neighbourhood": "Civic Center",
"city": "New York",
"county": "New York County",
"state": "New York",
"postcode": "10007",
"country": "United States of America",
"country_code": "us"
}
}
The output JSON contains various pieces of information about a specific location, including its geographic coordinates, address details, and other metadata.
-
place_id
: This is a unique identifier for the location, likely specific to the LocationIQ database. -
osm_type
: This field specifies the OpenStreetMap (OSM) type of the location. In this case, it's a "way," which typically represents a linear feature like a road or river in OSM data. -
osm_id
: This field contains the unique identifier for the OSM entity (in this case, a "way") within the OSM database. -
licence
: This is a URL that points to the attribution or license information for the data. It typically indicates the terms and conditions for using this data. -
lat
: This field represents the latitude coordinate of the location, which is approximately 40.712641. -
lon
: This field represents the longitude coordinate of the location, which is approximately -74.006087. -
display_name
: This field provides a human-readable representation of the location. It includes details such as the street address, neighborhood, city, county, state, postcode, and country. In this case, it corresponds to "260, Broadway, Civic Center, New York, New York County, New York, 10007, USA." -
boundingbox
: This field is an array that specifies the latitude and longitude coordinates that define a bounding box around the location. In this case, it seems to represent a single point, as both the minimum and maximum values for both latitude and longitude are the same. -
importance
: This field likely indicates the importance or significance of the location, with a value of 0.2. -
address
: This is an object that contains structured address information for the location. It includes fields like house_number, road, neighborhood, city, county, state, postcode, country, and country_code, providing detailed address information for the location "260, Broadway, Civic Center, New York, New York County, New York, 10007, USA."
4. Read the API Reference for more
You can tweak API responses to return less or more details, in a different format or apply additional cleaning by using additional parameters. Check the full API reference for more details.
Updated about 1 year ago