Convert Addresses To Coordinates

Use the Forward Geocoding API to transform Street Addresses to Coordinates

🔑

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 Address

Start with an address of your choice, for example 1600 Pennsylvania Avenue, Washington, D.C., United States.

Step 2: API Request

Craft a simple API request using LocationIQ's Forward geocoding API endpoint.

https://us1.locationiq.com/v1/search?key=YOUR_ACCESS_TOKEN&format=json&q=
  • https://us1.locationiq.com/v1/search: This is the base URL for the LocationIQ API's search endpoint. It's where you send your request to retrieve location information.
  • key=YOUR_ACCESS_TOKEN: This part of the URL is where you're supposed to substitute YOUR_ACCESS_TOKEN with an actual access token.
  • format=json: This parameter specifies the desired format for the response data. In this case, you're requesting the response data to be in JSON format
  • q=: This is a parameter that allows you to specify the query you want to search for. In the URL template you provided, it's left empty (q=).

Step 3: Parse Output

Parse the API output and capture the address elements you need. That's it!

[
    {
        "place_id": "349428694",
        "licence": "https://locationiq.com/attribution",
        "osm_type": "way",
        "osm_id": "899927559",
        "boundingbox": [
            "38.8958906",
            "38.8959158",
            "-77.030956",
            "-77.0308642"
        ],
        "lat": "38.8959025",
        "lon": "-77.0309076",
        "display_name": "Pennsylvania Avenue, Washington, District of Columbia, 20004, USA",
        "class": "highway",
        "type": "path",
        "importance": 0.585,
        "address": {
            "road": "Pennsylvania Avenue",
            "city": "Washington",
            "state": "District of Columbia",
            "postcode": "20004",
            "country": "United States of America",
            "country_code": "us"
        }
    }
]

Let's break down the different fields in the JSON response:

  1. "place_id": "349428694": This is a unique identifier for the place in LocationIQ's database.

  2. "licence": "https://locationiq.com/attribution": This is a link to the attribution information, which typically provides details about the terms of use or licensing for the data provided by LocationIQ.

  3. "osm_type": "way" and "osm_id": "899927559": These fields refer to OpenStreetMap (OSM) identifiers. OpenStreetMap is a collaborative mapping platform, and the osm_type indicates the type of OSM feature (in this case, a "way" which is typically a linear feature like a road), and the osm_id is the unique identifier for this feature on OSM.

  4. "boundingbox": ["38.8958906", "38.8959158", "-77.030956", "-77.0308642"]: These are the latitude and longitude coordinates that define a bounding box around the location. The format is [min_latitude, max_latitude, min_longitude, max_longitude].

  5. "lat": "38.8959025" and "lon": "-77.0309076": These fields provide the specific latitude and longitude coordinates of the location.

  6. "display_name": "Pennsylvania Avenue, Washington, District of Columbia, 20004, USA": This is a human-readable representation of the location's address. It includes the road, city, state, postcode, and country.

  7. "class": "highway" and "type": "path": These fields describe the classification and type of the location. In this case, it's classified as a highway and the type is a path.

  8. "importance": 0.585: This is a measure of the location's importance within the map data, with higher values indicating greater importance.

  9. "address": This is an object containing detailed address information broken down into components.

    • "road": "Pennsylvania Avenue": The name of the road.
    • "city": "Washington": The city where the location is situated.
    • "state": "District of Columbia": The state or administrative region.
    • "postcode": "20004": The postal code.
    • "country": "United States of America": The country name.
    • "country_code": "us": The ISO 3166-1 alpha-2 country code.