Nov 10, 2009

Geocoding and Reverse Geocoding

How many people have a google map implemented into a web page and need to put a marker on an exact address within the map. Over the next two blog posts I will show you how to do this using geocoding. As Google states, "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), which you can use to place markers or position the map.


The following geocoding exercise will pull information from google using the address for the college of business which is 300 West Michigan Ave, Ypsilanti, MI

The first part of the process is to send the geocoding request using a REST request
http://maps.google.com/maps/geo?q=300+West +Michigan+Ave,+Ypsilanti,+MI&output=xml&oe=utf8&sensor=false&key=ABQIAAAAE7hs30ymlAm_4X305SntMRSvMRu_uxOrKH4eiP-mAjD5A6ggehSGm3tWp7Lc7PqCeEkyzlWZ5b1fww


Code Broken Down

Queried URL
http://maps.google.com/maps/geo?

This is the address that you want to retrieve coordinates for
q=300+West +Michigan+Ave,+Ypsilanti,+MI

This is the type of output file you want the data to be return in
output=xml (If you prefer a JSON format you can replace xml with JSON in this part of the string)

Encoding format of the response
oe=utf8

indicates whether the request is coming from a device embedded with a location sensor
sensor=false

This is where you put in your unique google key that is licensed for your website
key=insert your google key here

The outputted response is shown below:

Here is the XML file that returned from the query, as you can see at the bottom of the XML file the returned coordinates of the college of business is -83.6161001, 42.2411090


Here is the JSON file that was returned from the query, as you can see at the bottom of the JSON file the returned coordinates of the college of business is the same as the XML file

In the next blog post I will show you a basic way to use this coordinate to place a marker at this point on a google map

Enjoy!!

9 comments:

  1. Good posting man! We were working on that geocoding last class in our group. It's like you have read our minds. Thanks for the info. We're waiting for the second post.

    ReplyDelete
  2. Josh, thanks for the detailed posting on this new feature of Google Maps. I cannot believe all of the information that Google Maps provides..as an example...today I saw an article on a new feature that Google Maps are providing for the public regarding the H1N1 vaccinations. Not only are they showing the various locations where vaccinations are being administered, but they are also showing the total doses shipped to a particular state and the percentage of children under the age of 14 who have received the injections. They are, in their own way, creating a mashup by using current data from the health departments and area hospitals.

    ReplyDelete
  3. Thank you for your blog. It definatelly will be usefull for our project. I believe we alredy did that part, but atleast now we can see if we have implemeted it correctly. Can you help me with how can I pick a particular information from a proxy RSS feed ?

    ReplyDelete
  4. Good stuff. I used Yelp combined with Google Maps to place the markers relevant to the user search. One thing to note about Geocoding via Google Maps is that I believe I read somewhere that Google limits the number available to each developer. I may be mistaken on this as I read it a few weeks ago, but I think I recall something about a limit...It's worth looking into.

    ReplyDelete
  5. Thanks Josh, this will save me some reasearch time for my project. Currently i am thinking of adding google maps with locators to my personal project for iteration 3.

    ReplyDelete
  6. Great post Josh, several individuals from class are using Google maps. This should really help everyone with not only group but individual projects.

    ReplyDelete
  7. Patty,
    I was going blog about the flu shot mashup but decided to actually post about geocoding and what it can do for you. It is amazing what the availability of information can do for you.

    ReplyDelete
  8. Matt,
    good info regarding the geocoding limit. I will have to research this to see if it limits per request or some other criteria.

    ReplyDelete
  9. Josh I cant say thank you enough for your great and detailed blogs. I really like how you break down the code and explain what line is doing what. Your posts have been a super help to me and others. I am looking forward to your next post.

    ReplyDelete