From: altinsel Date: 2008-09-16T05:57:47+09:00 Subject: Re: ruby / rexml / xpath bug? The funny result is the Ron Jon store in Orange, CA (second from last)... On Sep 15, 1:59 pm, altinsel wrote: > Thank you for your reply, Robert.  Here is the code with output and > puts of the XML (the Stores are coming from a local database).  Does > this help? > > ##CODE## > > require 'open-uri' > require 'rexml/document' > > # Retrieve geocode information for all records in the Stores table > task :google_geocode => :environment do >   api_key=GOOGLE_MAPS_KEY > >     (Store.find :all).each do |store| > >       puts "\nStore: #{store.name}" >       puts "Source Address: #{store.full_address}" > >       xml=open("http://maps.google.com/maps/geo? > q=#{CGI.escape(store.full_address)}&output=xml&key=#{api_key}").read >       doc=REXML::Document.new(xml) > >       puts "Status: "+doc.elements['//kml/Response/Status/code'].text > >       if doc.elements['//kml/Response/Status/code'].text != '200' >         puts "Unable to parse Google response for #{store.name}" >       else >         puts doc >         doc.root.each_element('//Response') do |response| >           puts "****" >           puts response >           puts "****" >           response.each_element('//Placemark') do |place| >             # puts "****" >             # puts place.elements['//Point']; >             # puts "****" >             lng,lat=place.elements['Point/ > coordinates'].text.split(',') >             puts "  Result Address: " << place.elements['// > address'].text >             puts "  ID: " << place.attributes['id'] >             puts "  Latitude: #{lat}" >             puts "  Longitude: #{lng}" >             puts "^^^^^^^^^^^^^^^^^^^^^^^^^" >           end # end each place >         end # end each response >       end # end if result == 200 >     end # end each store >   end # end rake task > > ##OUTPUT## > > rake google_geocode > (in /Users/acar/Documents/Design/Code/magicmaponrails) > > Store: The Original Ron Jon Surf Shop > Source Address: 901 Central Avenue, Long Beach Island, NJ, 08008 > Status: 200 > 901 Central Avenue, Long > Beach Island, NJ, 08008200 code>geocode id='p1'>
901 Central Ave, Beach Haven, NJ 08008, USA address> xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>NJ AdministrativeAreaName>Beach Haven LocalityName>901 Central Ave ThoroughfareName>08008 PostalCodeNumber> Country>-74.107299,39.756819,0 coordinates> > **** > 901 Central Avenue, Long Beach Island, NJ, 08008 name>200geocode Status>
901 Central Ave, Beach Haven, NJ > 08008, USA
xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>NJ AdministrativeAreaName>Beach Haven LocalityName>901 Central Ave ThoroughfareName>08008 PostalCodeNumber> Country>-74.107299,39.756819,0 coordinates>
> **** >   Result Address: 901 Central Ave, Beach Haven, NJ 08008, USA >   ID: p1 >   Latitude: 39.756819 >   Longitude: -74.107299 > ^^^^^^^^^^^^^^^^^^^^^^^^^ > > Store: One of aKind Ron Jon Surf Shop > Source Address: 4151 North Atlantic Avenue, Cocoa Beach, FL, 32931 > Status: 200 > 4151 North Atlantic Avenue, > Cocoa Beach, FL, 32931200geocode request>
4151 N Atlantic Ave, > Cocoa Beach, FL 32931, USA
xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>FL AdministrativeAreaName>Cocoa Beach LocalityName>4151 N Atlantic Ave ThoroughfareName>32931 PostalCodeNumber> Country>-80.608106,28.356747,0 coordinates>
> **** > 4151 North Atlantic Avenue, Cocoa Beach, FL, 32931 name>200geocode Status>
4151 N Atlantic Ave, Cocoa Beach, > FL 32931, USA
xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>FL AdministrativeAreaName>Cocoa Beach LocalityName>4151 N Atlantic Ave ThoroughfareName>32931 PostalCodeNumber> Country>-80.608106,28.356747,0 coordinates>
> **** >   Result Address: 4151 N Atlantic Ave, Cocoa Beach, FL 32931, USA >   ID: p1 >   Latitude: 28.356747 >   Longitude: -80.608106 > ^^^^^^^^^^^^^^^^^^^^^^^^^ > > Store: Ron Jon Surf Shop - Sunrise > Source Address: 2610 Sawgrass Mills Circle, Sunrise, FL, 33323 > Status: 200 > 2610 Sawgrass Mills Circle, > Sunrise, FL, 33323200geocode request>
2610 Sawgrass Mills Cir, > Fort Lauderdale, FL 33323, USA
xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>FL AdministrativeAreaName>Fort Lauderdale LocalityName>2610 Sawgrass Mills Cir ThoroughfareName>33323 PostalCodeNumber> Country>-80.315710,26.154207,0 coordinates>
> **** > 2610 Sawgrass Mills Circle, Sunrise, FL, 33323 name>200geocode Status>
2610 Sawgrass Mills Cir, Fort > Lauderdale, FL 33323, USA
xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>FL AdministrativeAreaName>Fort Lauderdale LocalityName>2610 Sawgrass Mills Cir ThoroughfareName>33323 PostalCodeNumber> Country>-80.315710,26.154207,0 coordinates>
> **** >   Result Address: 2610 Sawgrass Mills Cir, Fort Lauderdale, FL 33323, > USA >   ID: p1 >   Latitude: 26.154207 >   Longitude: -80.315710 > ^^^^^^^^^^^^^^^^^^^^^^^^^ > > Store: Ron Jon Surf Shop - Orlando > Source Address: 5160 International Drive, Orlando, FL, 32819 > Status: 200 > 5160 International Drive, > Orlando, FL, 32819200geocode request>
5160 International Dr, > Orlando, FL 32819, USA
xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>FL AdministrativeAreaName>Orlando LocalityName>5160 International Dr ThoroughfareName>32819 PostalCodeNumber> Country>-81.450308,28.469598,0 coordinates>
> **** > 5160 International Drive, Orlando, FL, 32819 name>200geocode Status>
5160 International Dr, Orlando, FL > 32819, USA
xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>FL AdministrativeAreaName>Orlando LocalityName>5160 International Dr ThoroughfareName>32819 PostalCodeNumber> Country>-81.450308,28.469598,0 coordinates>
> **** >   Result Address: 5160 International Dr, Orlando, FL 32819, USA >   ID: p1 >   Latitude: 28.469598 >   Longitude: -81.450308 > ^^^^^^^^^^^^^^^^^^^^^^^^^ > > Store: Ron Jon Surf Shop - Key West > Source Address: 503 Front Street`, Key West, FL, 33040 > Status: 200 > 503 Front Street`, Key West, > FL, 33040200geocode Status>
503 Front St, Key West, FL 33040, > USA
xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL: > 2.0'>US CountryNameCode>FL AdministrativeAreaName>Key West LocalityName>503 Front St > read more »