Helpful tips when working with Google Maps API: Geocoding and Places Service
Are you developing an application that needs details about a specific place? The Google Maps Platform may be what you are looking for. Using the Google Maps Platform, you can add maps and location to your iOS, Android and web apps.
Among the many Google Maps APIs are the Geocoding Service and the Places Service. These services help users find specific places using phone numbers, addresses, and more.
All are available to use by the public – all you need to do is obtain an API Key and ensure these services are enabled in your Google Cloud account.
What's the goods on these services?
Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739).
Reverse geocoding is the process of converting geographic coordinates into a human-readable address (see Reverse geocoding (Address Lookup)).
Places Service contains methods related to searching for places and retrieving details about a place (see PlaceResult interface for more details).
Tips for using libraries
While the Geocoding Service doesn't require any manually specified libraries to be used, the Places Service requires the
Tips for retrieving the full name of a business
When retrieving basic information of a place via their address, utilize Places Service for its findPlaceFromQuery() function. This function takes 2 parameters: a request (
FindPlaceFromQueryRequest), and a callback function. However, if you specify the street address (i.e. "1313 Disneyland Dr, Anaheim, CA 92802"), you may receive the name field as "1313 Disneyland Dr" instead of the full name of the business ("Disneyland Park").
To fix this, you must include a part of the full name in your request (and the exact address does not have to be used either!) In this case, the address used in the request would be "Disneyland, Anaheim, CA" or even "Disneyland 92802", which would return with the desired business name "Disneyland Park".
Tips for retrieving details about a place
When retrieving detailed information of a place, you can either use Places Service's findPlaceFromQuery() or getDetails() functions. To receive details, the findPlaceFromQuery() function requires an address and explicit specification of
['ALL'] as the fields value to get the available subset of the details from findPlaceFromQuery(). In contrast, getDetails() requires a Place ID and defaults the fields value to
['ALL'] if nothing is passed in. In addition, the getDetails() function will provide additional detailed values that are specific to only the getDetails() function (see PlaceResult interface).
If you need getDetails() for more detailed information than what findPlaceFromQuery() provides, you will first need to get the Place ID of your desired place first, i.e. via Geocoder.geocode(), PlacesService.findPlaceFromPhoneNumber(), or PlacesService.findPlaceFromQuery(). Once you have the Place ID, you may pass it into the getDetails() function and retrieve your detailed data.
Final things to remember
Getting details of a place through Google Maps API is very feasible, but if you run into issues, it is possible that you need to change the format of your address inside the request sent.
You may not need to specify the exact address. Instead, include a small portion of the business name in the request. Moreover, if you need more details of a place than what you currently receive, you'll need to go through the two-step process of obtaining the Place ID of your place and using it in Place Service's getDetails() function.
Lastly – don't forget to include the Places library and enable the services in your Google Cloud account.
We hope this article helps you navigate the Google Maps Places services. We'd love to hear from you, so feel free to get in touch!
- Geocoding Overview: https://developers.google.com/maps/documentation/geocoding/overview
- Places Service Overview: https://developers.google.com/maps/documentation/places/web-service/overview