Tuesday, December 25, 2012

Using Google Maps API for Location based Applications

If you want to create an application that needs to use location based services you can use the Google maps API.Maps API or Application programming interface has a set of functions that can be used in location based apps, Visualize Geo-spacial data,Maps for mobile,Customizing your map and so on.Google offer these API for developers for free and can be used in your web application.Generally the functions in the APIs are called  using JavaScript (i.e Client side script)  .If you want to know more just feel free to go through the APIs and learn how to use them.As a beginner tutorial i will teach you how to find the coordinates of a particular place using the Google APIs in PHP. By this tutorial beginners have a feel about the API and the intermediate user can learn how to use Google API in PHP(i.e server side script).


In this tutorial i have used the PHP function file_get_contents() for reading the entire file into a string.The file here refers to the file returned by the API.Once the string is obtained i use preg_match() to match a regular pattern and retrieve the Latitude and longitude of the given place.

If you want to try out a live demo type this in your URL "http://coordinates.herokuapp.com/?message=coimbatore". Try changing the message to different places and try again.It is a little buggy when you try entering every specific place but works well for cities.

If you want to have a peek or download the source code you can find it here.

If you have any doubts or need further assistance contact me or comment or use the drop box.
Stay tuned for more tutorials.

0 comments:

Post a Comment