Listing 2: mashup2.rhtml

<% require 'net/http' %>
<% require 'rexml/document' %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script

src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAQQK9JhAXQ9eq-G55q\
gu1ExTnGAXa-Bs2i826H4DeSQaC3Vqy-xSjDFaTYAO0N5YPQWIEeUbqJMhhbA"
    type="text/javascript"></script>
  </head>
  <body>
    <h2>Here is your map</h2>
    <div id="map" style="width: 400px; height: 400px"></div>
    <script type="text/javascript">

    var map = new GMap(document.getElementById("map"));
    map.centerAndZoom(new GPoint(-87.740070, 42.037030), 13);

    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());

<% final_list = [ ] %>
<% cities = ["Skokie,IL,US", "Longmeadow,MA,US",
             "Somerville,MA,US", "Old+Westbury,NY,US"] %>
<% cities.each_with_index do |city, index| %>
    <% geocoder_response =
        Net::HTTP.get_response('brainoff.com',
"/geocoder/rest/?city=#{city}") %>
    <% xml = REXML::Document.new(geocoder_response.body) %>
    <% longitude = xml.root.elements["/rdf:RDF/geo:Point/geo:long"].text
%>
    <% latitude = xml.root.elements["/rdf:RDF/geo:Point/geo:lat"].text %>
    <% final_list << {'city' => city, 'longitude' => longitude,
'latitude' => latitude } %>
    var myMarker<%= index %> = new GMarker(new GPoint(<%= longitude %>,
<%= latitude %>));
    map.addOverlay(myMarker<%= index %>);
<% end %>
    </script>

<body>


<h2>Your cities</h2>
<table border="1">
    <tr>
        <th>City</th>
        <th>Longitude</th>
        <th>Latitude</th>
    </tr>

<% final_list.each do |city| %>
    <tr>
        <td><%= city['city'] %></td>
        <td><%= city['longitude'] %></td>
        <td><%= city['latitude'] %></td>
    </tr>
<% end %>

</table>

</body>
</html>

