If you’ve worked with the Google Maps Platform or the HERE Location Platform you know that to add a map to your application, you need a latitude and longitude coordinate to center the map. You may still be wondering how to find a meaningful coordinate in the first place. That’s what a Geocoder is for – taking a free-form address entered by your application’s users and translating it into a place on a map.
For making REST API calls, the Google Places Geocoding API requires an API KEY whereas the HERE Geocoding Service requires an APP_ID and APP_CODE. You can retrieve the credentials from your Projects console when you sign up for an account with https://developer.here.com.
Regardless of your client programming language, this boils down to a GET request like the following:
As you can see, the parameters on these endpoints are similar – just credentials and a query string. You can use a command like curl or a tool like postman to view the corresponding results. A full description of the response returned is described in the HERE Geocoder API Guide, but a few of the more frequently used data use cases are compared below.
Is This the Correct Match?
In this particular case the address was unique, so we found only a single zero-indexed result in our set. For more ambiguous queries it wouldn’t be uncommon to find multiple locations returned.
|match = response[“results”]||match = response[“Response”][“View”][“Result”]|
The HERE Geocoder API includes some additional detail in the response that can be helpful if you are migrating from Google Places. Depending on the application you are building, you may want to take the quality values into consideration in how confident your application considers the match as the intended location.
Getting the Coordinates
The latitude and longitude can be found in the corresponding attributes.
You can see both return a result with a high precision. In addition to a single point, the result set includes a bounding box. The Google Geocoder API returns northeast and southwest coordinates whereas the HERE Geocoder API provides TopLeft and BottomRight.
Finding the Full Address
Our search query didn’t include the zip code or country, but the response includes a full human readable and valid postal address.
2168 Shattuck Ave, Berkeley, CA 94704, USA
2168 Shattuck Ave, Berkeley, CA 94704, United States
Additionally, the components of the address are broken out as separate values. If you were only interested in identifying the zip code there is no need to parse the address with a regex as the components have already been codified.
for each component in match[“address_components”]
for each type in component[“types”]
if type == “postal_code” then
Reference a Unique Place ID
A globally unique identifier (guid) is assigned by each platform for use in additional queries. The value has no meaning itself, but it can sometimes be helpful to use as an ID.
The Geocoding API allowed us to extract the latitude and longitude for a street address. We could create a dynamic map to display the point or identify interesting places using the Places Search API, which is the topic of the next post in this series.
Please reach out or comment to let us know what you think and what it is you want to see more of.