Pragmatic Friday Free Book - Google Maps and Ajax

The most recent short book release by Pragmatic Programmers is titled - Google Maps and Ajax. It outlines and explains how to hookup Google Maps, Geo Coding and AJAX to create a simple mashup.

3 Responses to “Pragmatic Friday Free Book - Google Maps and Ajax”

  1. Nathanael de Jager said on November 30th, 2005 at 2:42 pm

    That’s a pretty good chapter from an excellent book. In the chapter it talks about consuming a REST XML feed using JSP. If you are in Canada and are a Rails developer you might have wondered how you can consume the geocode.ca REST service in RoR to display Canadian Google Map locations. Since there aren’t any tutorials out there on how to do this, I thought I’d share what I do:

    In my controller I choose the function used to display my map and I type in the following code:

    # first I create a new connection to geocode.ca using port 80
    mappoint = Net::HTTP.new(’geocoder.ca’, 80)

    # next I set up my REST query.
    # note you more than likely would use escaped values from
    # your db instead of a hardcoded address.
    # make sure to read through the geocode.ca api for further addressing options!
    response = mappoint.get(”?locate=395+Wellington+Street+Ottawa+ON&geoit=xml”, nil)

    # next I place the body of the XML in a variable
    document = REXML::Document.new(response.body)

    # and finally I XPath through the XML body, grab the longitude
    # and lattitude values, and place them in instance variables.
    @long = REXML::XPath.first(document, “/geodata/longt”).text
    @lat = REXML::XPath.first(document, “/geodata/latt”).text

    After that I feed my geocode points to my Rails Google Map - there are a few Rails libraries out there that will handle Google Maps for you. My favorite is Cartographer - http://cartographer.rubyforge.org/.

    Happy Mapping Eh. :)

  2. DAvid said on May 16th, 2006 at 10:27 pm

    Thank you very much for this piece of code. It’s exactly what I needed! I just pasted your code snippet in my app and it works fine. I thought programming this feature would take me a few hours, but, thanks to you, it didn’t even take 5 minutes! I’m glad I stumbled upon your site.

    Thanks again

    DAvid

  3. freeland said on May 26th, 2006 at 7:18 am

    i try to find something at google.com and take it on your site…thanks