Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

algorithm for getting time zone from geo coordinates

I want to write app where user can point any place on map (not only cities) and get timezone in that place.

What data structure (app will not have Internet connectivity) and algorithm should I use? Where I can obtain needed data (I wont more accuracy then divining map into 24 rectangles)?

I will write my app in Java ME.

like image 522
Maciek Sawicki Avatar asked Dec 06 '09 13:12

Maciek Sawicki


People also ask

How do you calculate time zone using latitude and longitude?

We must start by finding the difference in longitude (or degrees) of the two places. We do this by adding the two numbers. Then, divide by the 15 degrees that occurs in one hour and this will give you the time difference between two locations through the International Date Line.

How do you determine a time zone?

To find the time zone in hours of a particular location, you can take the longitude -- in degrees -- and divide it by 15. So, for example, 75° E would be 75/15 which equals 5. That translates to the time zone being 5 hours ahead of UTC or GMT time, which can also be labeled as UTC+5. Let's do another one.

How many time zones is divided by longitude?

The world is divided into 24 time zones. The course of one day is broken down to the seconds and calculated to define the correct time of a particular place. However, it is not that easy. The 24 time zones, created in accordance to each hour of the day, are theoretically drawn vertically like longitudes over the globe.

Does longitude dictate time zones?

The rotation of the Earth means that time zones are dictated by the lines of longitude connecting the two poles.


2 Answers

Given that time zones are based on political entities rather than simply a physical lat/lon computation, I would create a data structure that mapped polygons over lat/lon coordinates into political entities (country and province/state) and then have a separate structure that mapped political entities and current date into timezone offset.

That way you not only avoid redundancy, but also:

  1. You can display DST reference information independently of a specific set of coordinates, and
  2. When some country changes the rules for when daylight saving time begins and ends, you have one place to make the update.

However, given the highly irregular shape of some borders, you'll need a fairly large data structure for accuracy, depending on the resolution of your input and/or display.

like image 177
joel.neely Avatar answered Nov 15 '22 14:11

joel.neely


There are a number of web services that can do this for you (for example GeoNames has a great API). But if you don't have an Internet connection, then that's not something you're going to find directly in Java ME's standard libraries.

You could do something close, though: Store the coordinates of the cities corresponding to each time zone, then do a Voronoi tessellation so that you have the areas which are closest to each city. Then, when your users click on a particular geographic area, you simply map that point to the right section of the tessellation, and presto -- you've got the nearest city, which in turn determines the right time zone.

More sophisticated approaches are possible, but they also require significantly larger memory structures, which I assume is a constraint if you are running Java ME. This is a good compromise between space and speed.

like image 27
John Feminella Avatar answered Nov 15 '22 14:11

John Feminella