Google Places API

Introduction

In a recent project at Redweb we had to provide a predictive location lookup and we were looking in to a bespoke solution using a postcode lookup service. The general functionality of the solution was to

  • Take a location string
  • Lookup in the postcode database the correctly location
  • Provide these via a WEB API service so that a we could create the suggestion box via JavaScript

However due to the fact that postcode data structure is flat and each record is primarily related to a postcode or primary address line this could not work. However we managed to find a little gem of a solution completely free from Google that despite some initial worries does the job perfect.

Places API

We at Redweb have used the Google Maps V3 API many a time for plotting map information but we had not come across the Places API. Essentially the places API allows you to look up places information as seen below.

Places auto complete screenshot

The Google Places API comes in the following 2 flavours both of which allow you to pass in a query location and set of restrctions

  • JavaScript Library – This library allow you to just references the Google JS file and use some simple code
  • Service API – This allows you to call the API directly and deal with the results yourself

Concerns

The main problem we found during using this was the fact the documentation is not well structures for this API. We wanted to use the JavaScript Library but from everywhere we could find it looked like the number of calls you could use was limited. There was information that if you register a billable card and create an API key you could have up to a 100,000 hit however there seems not way to do this in the JavaScript library only the Service API.

However we finally found a small area of text that states that the limit of calls is down to fair usage and on the JavaScript API the limit is via the client machine. Ergo each user of the website would have their one call limit which means for the site we would have an exponential limit which would more than cover.

Also to note both services require you when not using them with a map in the same area to display the powered by Google logo. By area I mean if you have a search on one tap that opens another with a Google map it’s required but if they are both viewable together it is not. The JavaScript Library auto adds this by default on the bottom of the result listing.

Solution

With the information we found we chose to go with the JavaScript Library as this does exactly the job we need.

Round Up

JavaScript Library

  • Easy to use
  • Limits based on end user given virtually limitless use
  • Configurable and easy to restrict country or place types

Service API

  • More powerful
  • Allows registering a billing card (no costs are ever incurred) that gives up to 100,000 calls when the API key is passed in
  • Allows use on a server side or C# application

Conclusion

This API is a really good service for use if you ever want to lookup places, it’s super easy to use and little restriction. The only caveat is having to display the powered by Google Logo but personally I like it.

 References

About ScottReed

I am an ASP.NET C# developer working in the south of England current for the south's top digital agency Redweb. I have worked for financial companies, CMS vendors, charities and web agencies tacking a variety of challenges. As part of my jobs and freelance I have done lots of work for high profile companies, big brands and government bodies and worked on some exciting large award winning builds. I love development and enjoy architectural design of software. ScottGu is my .NET hero and the Guru of all thing M$oft