Last active
December 23, 2015 19:59
-
-
Save brianfoshee/6686760 to your computer and use it in GitHub Desktop.
Comparing geocoders: Google vs Nominatim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'geocoder' | |
# (b-a)*prng.rand + a | |
def random(a,b) | |
(b-a) * rand() + a | |
end | |
# -90 -> 90 | |
def random_lat | |
random(-90, 90) | |
end | |
# -180 -> 180 | |
def random_lng | |
random(-180, 180) | |
end | |
def locs | |
@locs ||= 50.times.map { { location: "#{random_lat}, #{random_lng}" } } | |
end | |
def lookup(service) | |
locs.map! do |loc| | |
sleep 1 | |
r = Geocoder.search(loc[:location]).first | |
if r.nil? | |
loc.merge "#{service}" => nil | |
else | |
loc.merge "#{service}" => r.address | |
end | |
end | |
end | |
def print_results | |
locs.each_with_index do |loc, i| | |
next if loc['google'].nil? && loc['nominatim'].nil? | |
puts "\n*** #{i} ***\ngoogle : #{loc['google']}\nnominatim : #{loc['nominatim']}" | |
end | |
end | |
puts "Looking up google" | |
Geocoder.configure( | |
lookup: :google, | |
timeout: 10 | |
) | |
lookup('google') | |
puts "Looking up nominatim" | |
Geocoder.configure( | |
lookup: :nominatim, | |
timeout: 10 | |
) | |
lookup('nominatim') | |
print_results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** 1 *** | |
google : Antarctica | |
nominatim : | |
*** 3 *** | |
google : Indonesia | |
nominatim : South Sulawesi, Indonesia | |
*** 5 *** | |
google : Panna Khajuraho Road, Panna National Park, Madhya Pradesh 488001 | |
nominatim : Hinnauta, Panna, Madhya Pradesh, India | |
*** 7 *** | |
google : Antarctica | |
nominatim : Antarctica | |
*** 8 *** | |
google : Oymyakonsky District, Sakha, Russia | |
nominatim : Нелькан, Оймяконский улус, Sakha (Yakutia) Republic, Far Eastern Federal District, Russian Federation | |
*** 9 *** | |
google : Antarctica | |
nominatim : | |
*** 12 *** | |
google : Antarctica | |
nominatim : | |
*** 13 *** | |
google : Antarctica | |
nominatim : | |
*** 14 *** | |
google : Antarctica | |
nominatim : | |
*** 17 *** | |
google : Antarctica | |
nominatim : | |
*** 19 *** | |
google : Antarctica | |
nominatim : | |
*** 21 *** | |
google : Antarctica | |
nominatim : Ross Dépendency (New Zealand Claim) | |
*** 24 *** | |
google : Range Road 103, Youngstown, AB T0J 3P0, Canada | |
nominatim : Range Road 103, Alberta, Canada | |
*** 25 *** | |
google : Olenekskiy Natsionalnyy ulus, Sakha, Russia | |
nominatim : Olenyoksky Ulus, Sakha (Yakutia) Republic, Far Eastern Federal District, Russian Federation | |
*** 26 *** | |
google : DJ225, Romania | |
nominatim : DJ225, Mireasa, Constanța, 907279, Romania, European Union | |
*** 27 *** | |
google : | |
nominatim : Арзан | |
*** 30 *** | |
google : Foot Trail, Gambell, AK 99742, USA | |
nominatim : Gambell, Nome, Alaska, United States of America | |
*** 33 *** | |
google : Antarctica | |
nominatim : | |
*** 35 *** | |
google : Alto Amazonas, Peru | |
nominatim : Alto Amazonas, Department of Loreto, Peru | |
*** 37 *** | |
google : | |
nominatim : Hawaii, United States of America | |
*** 38 *** | |
google : Antarctica | |
nominatim : Antarctica | |
*** 40 *** | |
google : Antarctica | |
nominatim : | |
*** 41 *** | |
google : Antarctica | |
nominatim : | |
*** 44 *** | |
google : | |
nominatim : South Sandwich Islands, South Georgia and the South Sandwich Islands | |
*** 46 *** | |
google : ĐT723, Đạ Sar, Lạc Dương, Lam Dong, Vietnam | |
nominatim : 723, Dalat, Lam Dong province, Vietnam | |
*** 47 *** | |
google : | |
nominatim : Krasnoyarsk Krai, Siberian Federal District, Russian Federation | |
*** 49 *** | |
google : | |
nominatim : Luba, Bioko Sur, Región Insular, Equatorial Guinea |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment