How to Convert Address to GPS Coordinates

A couple of days Google released a new location API that lets you turn and address to GPS coordinates and vice versa. While you could do this using the Google Maps API this new way of doing it is a lot easier.

How It Works

This API is RESTful, you can get the data in two different formats, XML or JSON.

All you need to do is make a call to the the following URL.

From Address to Latitude and Longitude

Let’s get the latitude and longitude for "22 Cortlandt Street, New York, NY" in XML . Paste the following URL in your browser.,%20New%20York,%20NY&sensor=false

You actually get more than just the latitude and longitude, but the coordinates you want are in the <location> tag.


From GPS Coordinates to Address

To turn GPS coordinates back to an address you would replace &qout;address&qout; with "latlng&qout; and put the coordinates in that order separated by a coma. Let’s get our previous address using the location coordinates we just got.,-74.0107080&sensor=false

How to Use This Data in a Web Application

You can use your favorite language to read this API’s response. I have written several PHP tutorials on how to read xml from a URLand how to read json also from a URL or local file.

blog comments powered by Disqus