Maps are powerful tools that can be used in a variety of situations, from visualizing where customers live, to defining sales territories, to plotting crime patterns in neighborhoods. The first step in creating a map is to convert street addresses to latitude and longitude coordinates through a process called geocoding. You may not realize it, but you already encounter geocoding each time you type an address into a service like Google Maps or look up the school district for a property that is listed for sale on a real estate website.
This article will show you the steps for converting street addresses into latitude and longitude coordinates using the LatLon.io geocoding API.
Step 1: Get your API Token
To make a request to the geocoding API, you will need a valid API token. Log in to your account at LatLon.io and navigate to your account page. Your API token will be visible on your account page and looks like a long string of random letters and numbers.
Step 2: Format your Request
Your request should be in the format:
For example, if your API token was “abc123” and you wanted to geocode the address of the White House, your request would be:
Notice that the address field has been URL encoded, which means that the special characters like spaces and commas have been converted to “%20” and “%2C” respectively. URL encoding ensures that no matter what special characters the address contains, it will still be a valid web address.
Step 3: Make the Request
The easiest way to make your request is to just paste the url from step 2 into a Web browser. You can also make the request via the cURL command in your terminal, your programming language of choice, or with an interactive REST client like Advanced REST Client. For code samples in many popular languages, visit the interactive console on the LatLon.io documentation. To view a code sample in your favorite language:
- Enter your values for the address and token fields in the console
- Click “Call Resource”
- Select the “Code Example” tab and select your favorite language