开发者

How to validate a GPS coordinate against a timezone in RAILS

I have my users set their timezone in their preferences but we also attempt to grab a GPS coordinate from the br开发者_StackOverflow社区owser on each interaction. I would like to warn the user to change their timezone if the GPS coordinate fall within the specific timezone.

What methods can be used?

I'm currently using Rails 3.1


You can divide the latitude by 15° and then round to the nearest integer to get the "natural" timezone offset in hours. But that will only help you on the high seas, because on land the timezone boundaries differ significantly from the mathematically ideal ones. In some places, such as western China, the official time can differ from the geographically standard one by as much as 3 hours (which is even before adjusting for daylight saving).

So unless you embed a detailed map of timezone boundaries (which would be large and require some kind of updating mechanism as local and national governments decide to move around the timezones), the best you could hope to do would be to detect reliably is if your user flies intercontinentally but forgets to change his timezone. Unless you have a very specific audience, that is probably not worth the trouble.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜