0

I am using the java method TimeZone.getDefault() on an Android device to get my current timezone.

I need to extract any latitude longitude pair within the boundaries of the timezone. preferably the center, but it doesn't have to be exact.

Is there some Timezone boundaries data somewhere or some other way to achieve this?

Rationale: I have a 3rd party API that I am required to use for certain functionality, and while the API works well for what it does, it is no longer in active development and is not open-sourced.

The API requires a Latitude, Longitude pair to determine timezone, and has no public alternative to provide a timezone instead. I would rather not ask my users for location permission for an exact location if I can get away with it.

Vasili Fedotov
  • 1,091
  • 14
  • 31
  • Timezones are not straight. There is no "center"... – f1sh Aug 02 '20 at 13:32
  • yes, but they all have boundaries, I just need a single location within the timezone. I can find it myself If I get the boundaries – Vasili Fedotov Aug 02 '20 at 13:34
  • what are you trying to achieve? do you need the users time zone or the lat lon? – Sergey Aug 02 '20 at 13:50
  • I have the users time zone, and I don't need the users location. Just a location that is within the same time zone so I can pass it along to an API. – Vasili Fedotov Aug 02 '20 at 13:51
  • I used this api http://ip-api.com/json for getting the timezone in some project, there is also a lat lon fields provided maybe it can help you – Sergey Aug 02 '20 at 13:54

1 Answers1

1

I can think of two relevant data sources that would be useful here:

  • The IANA TZDB contains two files, zone1970.tab and zone.tab. These lists are designed to assist with time zone selection, and contain coordinates for each of the cites that serve as reference points, for the time zones listed.

  • The Timezone Boundary Builder project has shapefiles containing the approximate geographic boundaries for each time zone. This is used by many libraries (as listed here) that are focused on the problem of lat/lon to timezone. You appear to be interested in going the other direction, which will require some analysis work on your part. Basically, you would need to use the polygon shapefiles from that project and pick a point at random from within a polygon associated with the time zone in question.

With either approach, you may first need to resolve aliases to their canonical counterparts. For example, if you have US/Eastern, you'd need to resolve that to America/New_York before attempting to look it up in either data source.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575