Fetching Data from Google Places API Using Titanium

Fetching Data from Google Places API Using Titanium

August 11, 2012

The Google Places API is a new part of Google Maps and returns information about places, e.g. banks, atms, airports and more. I have written this brief Javascript wrapper and a sample call to show you how easy it is to retrieve data from the Places API using Titanium!

First up you'll need an API key, you can fetch one from the Google API's Console here: https://code.google.com/apis/console.

Once that is done, create a new file in your existing project (or create a new project if you want), and call that new file "placesapi.js". In it, paste the following code:
Now in your app.js file (or wherever you intend to call the API from), you can use the following sample call to get data back using our API wrapper. Note while you can return XML data from this API I am only using JSON which should really be your de-facto standard for any mobile development. Note you'll have to replace the XXXXXXXXXXXXXXXXXXX API key with your own valid API key from Google.
You can also get place information by calling the getPlaceDetails method using the "reference" parameter like this:
Feel free to share or extend this code however you want. There's other methods available for adding places and more so if anyone feels like doing that and share it go ahead! If you find any mistakes in the code feel free to send me a message and I'll fix it up.