Skip to content

Commit

Permalink
corrections
Browse files Browse the repository at this point in the history
git-svn-id: http://ym4r.rubyforge.org/svn/Plugins/GM/trunk/ym4r_gm@93 c9bc9743-7714-0410-b404-d8b1d4e1ace9
  • Loading branch information
Guilhem Vellut committed Jun 6, 2007
1 parent 0756e59 commit ab156d8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
24 changes: 12 additions & 12 deletions lib/gm_plugin/geocoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.get(request,options = {})
api_key = ApiKey.get(options)
output = options[:output] || "kml"
url = "http://maps.google.com/maps/geo?q=#{URI.encode(request)}&key=#{api_key}&output=#{output}"

res = open(url).read

case output.to_sym
Expand Down Expand Up @@ -58,20 +58,20 @@ def self.get(request,options = {})
when :kml, :xml

doc = REXML::Document.new(res)

response = doc.elements['//Response']
placemarks = Placemarks.new(response.elements['name'].text,response.elements['Status/code'].text.to_i)
response.elements.each("Placemark") do |placemark|
response.elements.each(".//Placemark") do |placemark|
data = placemark.elements
data_country = data['//CountryNameCode']
data_administrative = data['//AdministrativeAreaName']
data_sub_administrative = data['//SubAdministrativeAreaName']
data_locality = data['//LocalityName']
data_dependent_locality = data['//DependentLocalityName']
data_thoroughfare = data['//ThoroughfareName']
data_postal_code = data['//PostalCodeNumber']
lon, lat = data['//coordinates'].text.split(",")[0..1].collect {|l| l.to_f }
data_accuracy = data['//*[local-name()="AddressDetails"]'].attributes['Accuracy']
data_country = data['.//CountryNameCode']
data_administrative = data['.//AdministrativeAreaName']
data_sub_administrative = data['.//SubAdministrativeAreaName']
data_locality = data['.//LocalityName']
data_dependent_locality = data['.//DependentLocalityName']
data_thoroughfare = data['.//ThoroughfareName']
data_postal_code = data['.//PostalCodeNumber']
lon, lat = data['.//coordinates'].text.split(",")[0..1].collect {|l| l.to_f }
data_accuracy = data['.//*[local-name()="AddressDetails"]'].attributes['Accuracy']
unless data_accuracy.nil?
data_accuracy = data_accuracy.to_i
end
Expand Down
3 changes: 2 additions & 1 deletion lib/gm_plugin/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class ApiKey
unless File.exist?(RAILS_ROOT + '/config/gmaps_api_key.yml')
raise GMapsAPIKeyConfigFileNotFoundException.new("File RAILS_ROOT/config/gmaps_api_key.yml not found")
else
GMAPS_API_KEY = YAML.load_file(RAILS_ROOT + '/config/gmaps_api_key.yml')[ENV['RAILS_ENV']]
env = ENV['RAILS_ENV'] || RAILS_ENV
GMAPS_API_KEY = YAML.load_file(RAILS_ROOT + '/config/gmaps_api_key.yml')[env]
end

def self.get(options = {})
Expand Down
9 changes: 8 additions & 1 deletion lib/gm_plugin/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def control_init(controls = {})
@init_end << add_control(GOverviewMapControl.new) if controls[:overview_map]
end

#Initializes the interface configuration: double-click zoom, dragging, continuous zoom,... You can pass a hash with keys <tt>:dragging</tt>, <tt>:info_window</tt>, <tt>:double_click_zoom</tt>, <tt>:continuous_zoom</tt>. The values should be true or false. Check the google maps API doc to know what the default values are.
#Initializes the interface configuration: double-click zoom, dragging, continuous zoom,... You can pass a hash with keys <tt>:dragging</tt>, <tt>:info_window</tt>, <tt>:double_click_zoom</tt>, <tt>:continuous_zoom</tt> and <tt>:scroll_wheel_zoom</tt>. The values should be true or false. Check the google maps API doc to know what the default values are.
def interface_init(interface = {})
if !interface[:dragging].nil?
if interface[:dragging]
Expand Down Expand Up @@ -98,6 +98,13 @@ def interface_init(interface = {})
@init << disableContinuousZoom()
end
end
if !interface[:scroll_wheel_zoom].nil?
if interface[:scroll_wheel_zoom]
@init << enableScrollWheelZoom()
else
@init << disableScrollWheelZoom()()
end
end
end

#Initializes the initial center and zoom of the map. +center+ can be both a GLatLng object or a 2-float array.
Expand Down
19 changes: 10 additions & 9 deletions test/gm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,25 @@ def test_array_indexing
end

def test_google_maps_geocoding


placemarks = Geocoding.get("Rue Clovis Paris")
assert_equal(Geocoding::GEO_SUCCESS,placemarks.status)
assert_equal(1,placemarks.length)
placemark = placemarks[0]
assert_equal("FR",placemark.country_code)
assert_equal("Paris",placemark.locality)
assert_equal("75005",placemark.postal_code)
end

def test_google_maps_pakistan
placemarks = Geocoding.get("Lahore PK")

#test iwht multiple placemarks
placemarks = Geocoding.get('hoogstraat, nl')
assert_equal(Geocoding::GEO_SUCCESS,placemarks.status)
assert_equal(1,placemarks.length)
placemark = placemarks[0]
assert_equal("PK",placemark.country_code)
assert_equal("Lahore",placemark.locality)
assert_equal("",placemark.thoroughfare)
assert(placemarks.length > 1)
assert(placemarks[0].latitude != placemarks[1].latitude )


end


end

0 comments on commit ab156d8

Please sign in to comment.