2011-04-07 16:45:16 8 Comments
is there any possibility to determine the timezone of point (lat/lon) without using webservices? Geonames.org is not stable enough for me to use :( I need this to work in PHP.
Thanks
Related Questions
Sponsored Content
8 Answered Questions
[SOLVED] Why use Redux over Facebook Flux?
- 2015-09-08 15:05:14
- VB_
- 231466 View
- 1093 Score
- 8 Answer
- Tags: javascript reactjs reactjs-flux flux redux
18 Answered Questions
24 Answered Questions
[SOLVED] Determine a user's timezone
- 2008-08-01 00:42:38
- Kevin Dente
- 164297 View
- 564 Score
- 24 Answer
- Tags: html browser timezone user-agent timezone-offset
18 Answered Questions
[SOLVED] How to modify the URL without reloading the page?
- 2009-05-05 10:54:05
- Robinicks
- 1125872 View
- 1973 Score
- 18 Answer
- Tags: javascript html url url-rewriting friendly-url
7 Answered Questions
[SOLVED] How does PHP 'foreach' actually work?
- 2012-04-07 19:33:57
- DaveRandom
- 358557 View
- 1777 Score
- 7 Answer
- Tags: php loops foreach iteration php-internals
17 Answered Questions
[SOLVED] How to decide when to use Node.js?
- 2011-02-21 05:20:51
- Legend
- 479781 View
- 2199 Score
- 17 Answer
- Tags: javascript node.js web-applications
14 Answered Questions
[SOLVED] How to get a time zone from a location using latitude and longitude coordinates?
- 2013-04-18 15:24:09
- Matt Johnson
- 173827 View
- 245 Score
- 14 Answer
- Tags: geolocation timezone latitude-longitude
9 Answered Questions
[SOLVED] How do you use bcrypt for hashing passwords in PHP?
- 2011-01-25 15:34:04
- Vilx-
- 351837 View
- 1186 Score
- 9 Answer
- Tags: php passwords cryptography password-protection bcrypt
1 Answered Questions
[SOLVED] Timezone from latitude and longitude in stata
- 2017-02-01 14:40:14
- eigenvector
- 120 View
- -2 Score
- 1 Answer
- Tags: geolocation stata
1 Answered Questions
[SOLVED] How to get timezone by latitude and longitude
- 2015-05-29 11:32:48
- Gurumahesh Vunna
- 2951 View
- 1 Score
- 1 Answer
- Tags: ios geolocation timezone
16 comments
@Ummar farook P 2017-01-07 06:43:25
@Sheena Singla 2016-05-17 10:30:20
You can use Google Timezone api.
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&key=YOUR_API_KEY
@Dieter Meemken 2016-05-17 10:33:08
Can you explain a bit more?
@Sheena Singla 2016-05-21 07:13:54
Hi @DieterMeemken , you can use Google Api as mentioned above. In this Google api you have to enter 1.latitude, longitude in location parameter 2. timestamp 3. your api key and it will return you the object containing parameter 'timeZoneId'.
@jzarsuelo 2016-11-02 05:02:18
You can check this link for more info: developers.google.com/maps/documentation/timezone/start
@Ervin Ruci 2015-11-23 19:08:04
I use geocoder.ca
Input any location in North America, Output geocodes, area codes and timezone in json or jsonp.
For example: http://geocoder.ca/1600%20pennsylvania%20avenue,Washington,DC
Area Code: (202) Time Zone: America/New_York
Json:
@Ben Wheeler 2015-06-19 21:35:34
I downloaded data that matches 5 digit zip codes to time zones, and data that determines the UTC offset for each time zone during DST and non-DST periods.
Then I simplified the data to only consider the first three digits of the ZIP Code, since all ZIP codes that share the first three digits are very close to each other; the three digits identify a unique mail distribution center.
The resulting Json file does require you to decide whether or not you are subject to DST currently, and it probably has some inaccuracy here and there. But it's a pretty good local solution that is very compact and simple to query.
Here it is: https://gist.github.com/benjiwheeler/8aced8dac396c2191cf0
@Steve 2014-01-10 01:09:56
Not sure if this is useful or not, but I built a database of timezone shapes (for North America only), which is painstakingly accurate and current not just for borders, but also for daylight saving time observance. Also shapes for unofficial exceptions. So you could query the set of shapes for a given location could return multiple shapes that apply to that location, and choose the correct one for the time of year.
You can see an image of the shapes at http://OnTimeZone.com/OnTimeZone_shapes.gif. Blue shapes are around areas that do not observe daylight saving time, magenta shapes those that do observe daylight saving time, and neon green shapes (small and tough to see at that zoom level) are for areas with unofficial deviation from the official time zone. Lots more detail on that available at the OnTimeZone.com site.
The data available for download at OnTimeZone.com is free for non-commercial use. The shape data, which is not available for download, is available for commercial license.
@Tim Cooper 2013-10-29 23:32:49
I've written a small Java class to do this. It could be easily translated to PHP. The database is embedded in the code itself. It's accurate to 22km.
https://sites.google.com/a/edval.biz/www/mapping-lat-lng-s-to-timezones
The whole code is basically stuff like this:
...so I presume a translation to PHP would be easy.
@Alastair 2013-12-02 15:43:50
Thanks for sharing. THis could be integrated via bash but @flexjack said that they
need this to work in PHP
explicitly.@Tim Cooper 2013-12-03 20:05:04
See edited answer. A PHP port would be dead simple.
@Alastair 2013-12-06 16:00:04
That would translate into practically any language but having the data in the code is inconvenience for updates and has presumably poor performance, at 30K+ lines. I'd be interested in testing the result, if you update your answer for PHP! :-)
@Christian Stade-Schuldt 2013-10-30 23:02:02
How exact do your results have to be? If a rough estimate is enough, calculate the offset yourself:
where direction is 1 for east, -1 for west, and longitude is in (-180,180)
@KarthikS 2015-05-03 02:17:44
Thanks really helpful answer, especially if accuracy is not an issue. I also rounded off the decimals in your formula.
@bfred.it 2018-04-06 07:23:39
That's a very rough estimate, only if you're ok having the wrong timezone very often (e.g. the whole Spain/France have a different timezone from London even if they have the same longitude. Map)
@j-bin 2013-03-20 21:58:24
How about this ?
@codecowboy 2013-10-16 06:46:31
Can you add some comments which explain how this function works?
@mindplay.dk 2017-08-30 13:32:38
@codecowboy he's searching the entire list of timezones, each of which specify a centroid for the timezone - this isn't reliable, but for lack of better, you might consider this a "best guess" implementation.
@Mikhail Krasnorutsky 2013-02-13 18:32:41
You can use time zone boundaries, provided here:
http://www.opensource.apple.com/source/TimeZoneData/
@Jeffrey Vdovjak 2013-01-27 06:50:56
I know this is old, but I spent some time looking for this answer. Found something very useful. Google does time zone lookups by long/lat. 2,500 per day limit (or 100,000 for business users).
https://developers.google.com/maps/documentation/timezone/
@themihai 2016-07-28 12:50:32
You don't need a webservice for that.
@MikeM 2012-12-12 22:16:58
Another solution is to import a table of cities with timezones and then to use the Haversine formula to find the nearest city in that table, relevant to your coordinates. I have posted a full description here: http://sylnsr.blogspot.com/2012/12/find-nearest-location-by-latitude-and.html
For an example of loading the data in MySQL, I have posted an example here (with sources for downloading a small data dump): http://sylnsr.blogspot.com/2012/12/load-timezone-data-by-city-and-country.html
Note that the accuracy of the look-up will be based on how comprehensive your look-up data is.
Credits and References: MySQL Great Circle Distance (Haversine formula)
@James D 2012-05-07 21:11:46
I ran into this problem while working on another project and looked into it very deeply. I found all of the existing solutions to be lacking in major ways.
Downloading the GeoNames data and using some spatial index to look up the nearest point is definitely an option, and it will yield the correct result a lot of the time, but it can easily fail if a query point is on the wrong side of a time zone border from the nearest point in the database.
A more accurate method is to use a digital map of the time zones and to write code to find the polygon in that map that contains a given query point. Thankfully, there is an excellent map of the time zones of the world available at http://efele.net/maps/tz/world/. To write an efficient query engine, you need to:
Each of those are worthy of their own Stack Overflow question/answer page.
After concluding that none of the existing solutions out there met my needs, I wrote my own solution and made it available here:
http://askgeo.com
AskGeo uses a digital map and has a highly optimized spatial index that allows for running more than 10,000 queries per second on my computer in a single thread. And it is thread safe, so even higher throughput is certainly possible. This is a serious piece of code, and it took us a long time to develop, so we are offering it under a commercial license.
It is written in Java, so using it in PHP would involve using:
http://php-java-bridge.sourceforge.net/doc/how_it_works.php
We are also open to porting it for a bounty. For details on the pricing, and for detailed documentation, see http://askgeo.com.
I hope this is useful. It certainly was useful for the project I was working on.
@Tim Parenti 2012-01-21 18:25:30
For areas on land, there are some shapefile maps that have been made for the timezones of the tz (Olson) database. They're not updated quite as regularly as the tz database itself, but it's a great starting point and seems to be very accurate for most purposes.
@sharky 2012-07-31 03:06:41
+1 Hi Tim, thank you -- I successfully used these maps in my project with GeoTools to convert from lat/long to time zone IDs, then Joda time to convert instantaneous time plus the time zone IDs to give localised historical times. Sweet.
@Michael Borgwardt 2011-04-07 17:03:23
I had this problem a while back and did exactly what adam suggested:
IIRC it took less than 1 second to populate the R-Tree, and it could then perform thousands of lookups per second (both on a 5 year old PC).
@Micah 2011-06-06 03:59:43
I've been searching for a solution for a while now and this is awesome. It may not be 100% accurate but it's good enough for what I need.
@Markos Fragkakis 2011-09-15 20:48:39
Sorry if this is not valid, but aren't R-Trees meant for rectangles? I thought that a nearest-neighbor algorithm, such as one using kd-trees was meant for points.
@Michael Borgwardt 2011-12-16 19:15:20
@Markos Fragkakis: Saw your comment just now. The R-Tree library I linked to has a nearest neighbour search. Not sure how exactly it is implemented. But the basic idea should work just as well with a different data structure.
@Markos Fragkakis 2011-12-17 20:24:53
Thanks for the last comment! I went for a KD-tree implementation in the end.
@Laurent Debricon 2012-02-08 13:36:32
I had so much pain to do the part 'convert it to a compact lat/lon -> timezone list' , here it is : gist.github.com/1769458. Then i used postgres with postgis, a Gist index on Geography type, and then the query : select timezone_string where ST_DWithin(ST_GeographyFromText('SRID=4326;POINT(2.36 48.86)'), location, 100000, false) order by st_distance(ST_GeographyFromText('SRID=4326;POINT(2.36 48.86)'), location) limit 1. I look 100km around the point I want (2.36 48.86) for decent perfs : 30ms. If it fails, i do 6000km : 1sec :)
@NuSkooler 2012-03-07 04:05:50
I created a simple Python scrip to convert GeoNames.org data (and other) to various formats such as MongoDB .json insert scripts for geospatial queries. It can be found here: github.com/NuSkooler/GeoToTimeZone
@hennings 2012-04-25 07:40:52
For finding the nearest city to a given coordinate, a quad-tree should be even faster (and simpler). en.wikipedia.org/wiki/Quadtree
@Michael Borgwardt 2012-04-25 07:59:58
@hennings: I don't think that would work - the nearest city could be in a completely different branch of the tree.
@jep 2014-11-11 23:10:49
Isn't this a pretty error-prone solution? For example, Jasper, TN is closest to Chattanooga, TN - and also in a different time zone. It seems like you'd probably get wrong results for most cities on the borders of time zones that aren't the cities listed in the geonames cities list. I know 100% accuracy is pretty impossible, but I'm not sure this is even close.
@Michael Borgwardt 2014-11-12 09:39:31
@jep: the list is pretty complete. But yes, there will often be wrong results when you've very close to a border. Depends on the application whether that's tolerable.
@daniellmb 2011-04-07 16:54:29
You should be able to, if you know the polygon of the timezone to see if a given lat/lon is inside it.
World Time Zone Database
Latitude/Longitude Polygon Data
@Jacek Francuz 2011-04-07 17:06:12
Ok. Isn't it very computational?
@Michael Borgwardt 2011-04-07 17:07:48
Note that for most purposes, you really need to distinguish the over 400 administrative timezones, not just the base offsets, due to different daylight savings switches and historical changes thereof.
@Pacerier 2011-12-28 15:16:07
Crap this is gd stuff, However wouldn't the data be dynamic instead of being static ? =)
@MillKa 2011-04-07 16:53:48
Unfortunately, time zones are not regular enough for some simple function. See the map in Wikipedia - Time Zone
However, some very rough approximation can be calculated: 1 hour difference corresponds to 15 degrees longitude (360 / 24).