X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/dcac9dfeca26b38d3a5eb16a2b0276b0e7619e22..f0c4e816b294c47907a803c5d8303ddaa67ea7fc:/lib/osm.rb diff --git a/lib/osm.rb b/lib/osm.rb index 77b07ce3d..3043eb395 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -5,7 +5,7 @@ module OSM # # This would print every latitude value: # - # gpx = OSM:GPXImporter.new('somefile.gpx') + # gpx = OSM::GPXImporter.new('somefile.gpx') # gpx.points {|p| puts p['latitude']} require 'time' @@ -364,4 +364,27 @@ module OSM return doc end end + + def self.IPLocation(ip_address) + Timeout::timeout(4) do + Net::HTTP.start('api.hostip.info') do |http| + country = http.get("/country.php?ip=#{ip_address}").body + country = "GB" if country = "UK" + Net::HTTP.start('ws.geonames.org') do |http| + xml = REXML::Document.new(http.get("/countryInfo?country=#{country}").body) + xml.elements.each("geonames/country") do |ele| + minlon = ele.get_text("bBoxWest").to_s + minlat = ele.get_text("bBoxSouth").to_s + maxlon = ele.get_text("bBoxEast").to_s + maxlat = ele.get_text("bBoxNorth").to_s + return { :minlon => minlon, :minlat => minlat, :maxlon => maxlon, :maxlat => maxlat } + end + end + end + end + + return nil + rescue Exception + return nil + end end