1

If I travel to a given part of the world iOS will automatically update the timezone. I'm curious if it uses GPS coordinates to do so, and if that's the case, are there any facilities in Swift to find out the timezone from a specific set of GPS coordinates?

I'm aware of NSTimeZone and none of its functions seem to do what I need. I'm calculating solar rise and set times for any specified location around the world. I.e. locations the user may not currently be in. However, the dates are returned in UTC so I need to be able convert those dates into their appropriate timezones.

The major constraint to this project, is that I can't use online API's such as GeoCities or Google.

I have considered using an offline database, I'm just seeing if Swift has a function I can use first.

fbailey
  • 303
  • 5
  • 17
  • 1
    Interesting solution, but yeah I see what you mean, it does require networked services :/ . – fbailey Mar 24 '15 at 23:06
  • Sorry, I deleted [that link](http://stackoverflow.com/questions/9188871/how-to-identify-timezone-from-longitude-and-latitude-in-ios/27054583#27054583) because after reviewing your question, it obviously doesn't meet your needs. How is the user specifying their location when something other than the current location? Could they be picking from a list of `[NSTimeZone knownTimeZoneNames]` (or some UI that they can navigate through that hierarchical structure)? Or convert those locations into a map and let them click on the one that is closest? – Rob Mar 24 '15 at 23:09
  • 1
    @Rob, there will be 2 ways of getting their location. Either via location services or a list of cities to choose from. If a city is chosen from the list, we'll convert it to coordinates from our local database. For usability's sake we're striving to keep it to a one click (pick a city) solution. – fbailey Mar 24 '15 at 23:30
  • Yeah, then maybe mapping your list of cities to the `knownTimeZones` list might do it, right? – Rob Mar 24 '15 at 23:46
  • Well there will be raw gps coordinates as well. We've elected to use a timezone database as it seems this facility doesn't exist in swift. Thanks for the time and effort put into your insights, though. – fbailey Mar 25 '15 at 03:12

1 Answers1

3

Alright, after much searching I have found an acceptable solution. Alterplay has an objective-c library that can calculate timezones based off of gps coordinates without the need to use online services. For anyone that's curious the library can be found here: https://github.com/Alterplay/APTimeZones .

fbailey
  • 303
  • 5
  • 17
  • Make sure to review the issues on that project. There are several reports of incorrect results. There may be others not yet reported. – Tom Harrington Mar 26 '15 at 16:28
  • 1
    Looking more closely, their approach is pretty much inaccurate by design. There will be a lot of correct answers, but also a whole lot of wrong answers. It's a bad approach prone to bad results. – Tom Harrington Mar 26 '15 at 16:47
  • @TomHarrington yes after doing some testing we found the same results. At this point we're going to consider it a fallback option when no connection is found. They have a Geocoder function implemented as well which can be used where Internet connections are available. – fbailey Mar 26 '15 at 19:29