panthomakos / timezone

Accurate current and historical timezones for Ruby with support for Geonames and Google latitude - longitude lookups.
http://rubygems.org/gems/timezone
MIT License
354 stars 49 forks source link

Improved matching from google #48

Closed jkotchoff closed 8 years ago

jkotchoff commented 8 years ago

The google service is returning a timezone of "Australia/Hobart" for co-ordinates which should instead be matching "Australia/Melbourne" ie.

Timezone::Zone.new(latlon: [-37.808916,144.967346]).zone
 => "Australia/Hobart"

Is this because both of those timezones share the same offset (UTC +10) and it's returning the first one from that list?

Perhaps this could be improved in the timezone gem by checking for multiple timezone matches on a query and returning the closest one geographically.

ie. Perhaps the gem could store a lat/lng center co-ordinate for each of the timezones specified in ActiveSupport::TimeZone::MAPPING and then before returning a matched timezone, it could check to see whether any of the other timezones that share the same offset and daylight savings time are a better match based on a closer geographical center point to the co-ordinates being queried.

panthomakos commented 8 years ago

@jkotchoff I don't know why Google is returning the incorrect timezone - this gem has no impact/influence on the Google API. I believe this is a bug that you should file with Google. Using a center coordinate to try to improve on the results returned from APIs is not practical as most countries and timezones are not based on central point - they are based on geo-political boundaries and can be rather arbitrary. I would suggest investigating in more detail the results returned from Google or GeoNames APIs. There might be something you can do with a custom HTTP handler to address your specific use-case. If there is some information returned in the Google API that is ranking or ordering results in a way that this gem does not account for, please do respond and re-open this ticket so that I can improve the ordering/matching.