How to Migrate from Google Places to HERE Geocoder

By Jayson DeLancey | 26 June 2018

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”][0]

match = response[“Response”][“View”][“Result”][0]

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.

"MatchLevel":"houseNumber",

"MatchQuality":{

"State":1.0,

"City":1.0,

"Street":[1.0],

"HouseNumber":1.0},

"MatchType":"interpolated"

Getting the Coordinates

The latitude and longitude can be found in the corresponding attributes.

match[“geometry”][“location”]

match[“Location”][“DisplayPosition”]

{

“lat”: 37.869768,

“lng”: -122.268468

}

{

“Latitude”: 37.86976,

“Longitude”: -122.26846

}

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.

match[“formatted_address”]

match[“Location”][“Address”][“Label”]

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

return component[“short_name”]

match[“Location”][“Address”][“PostalCode”]

94704

94704

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.

match[“place_id”]

match[“Location”][“LocationId”]

ChIJ56lMNJx-hYARU3cMPHQpwzs

NT_mYv2P3Ds2uTfo2vKqrWDEC_yEjN4A

What's Next?

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.

Jayson is a Senior Developer Evangelist with HERE Technologies in Berkeley, CA. He writes about his location technology experiences related to Web, IoT, and Robotics projects using a variety of technologies like ReactJS, Python, and Cloud Foundry. Jayson is an active advocate for maker and open-source communities. You can also find him on Twitter (@jaysondelancey) or LinkedIn (in/jaysondelancey).