We're using the Geocoder gem in our app. In a test, we're using the following address:
4 Cork Oak Rd, Welgevonden, Stellenbosch
Geocoding it returns the following coordinates:
[39] pry(main)> coord = Geocoder.search("4 Cork Oak Rd, Welgevonden, Stellenbosch")[0].geometry["location"]
=> {"lat"=>-33.9023262, "lng"=>18.851008}
But when I reverse geocode those exact coordinates, I get nothing:
[46] pry(main)> Geocoder.search("#{coord['lat']}, #{coord['lng']}")
=> []
What gives?!
As far as I can tell/remember, this issue is only happening as of today. It breaks every single time on my machine, and yet it hasn't failed once on Semaphore. No configuration changes have happened since Friday.
If I round the coordinates to 6 decimal places, I do get the desired result:
[55] pry(main)> Geocoder.search("#{coord['lat'].round(6)}, #{coord['lng'].round(6)}")
=> [#<Geocoder::Result::Google:0x0000011738bdd8
@cache_hit=true,
@data=
{"address_components"=>
[{"long_name"=>"Cork Oak Road"...
I'd like to find a solution that doesn't require altering precision where it never caused a problem before.
Just watched the Geocoder code, and i found the Geocoder.address()
function, i tried with your coordinates, and Geocoder.address('-33.9023262, 18.851008')
returns me Cork Oak Road, Stellenbosch
. I also tried with a 13 decimal latitude, it works too
Geocoder.search()
.Geocoder.address()
According to the code available on GitHub.
If you want complete informations about the place you can use Geocoder.search(Geocoder.address('-33.9023262, 18.851008'))
, but it is two HTTP requests sent to Google servers.
In my opinion, best solution is to round to 6 decimals and send only one request, you only lose 43.496 mm of precision.
You have to chose between an absolute precision or send two HTTP requests.