How to get any Latitude and Longitude pair within a timezone?
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.
I can think of two relevant data sources that would be useful here:
The IANA TZDB contains two files,
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.