Skip to content

friedbunny/TimeZoneCoordinate

Repository files navigation

NSTimeZone+Coordinate

Adds a coordinate property to NSTimeZone — useful in situations where location permission has not yet been granted, has been refused, or can’t be requested.

These coordinates are derived from the IANA’s Time Zone database and represent the largest populated place within a given time zone (not the centroid).

Example map showing pins at timezone coordinates

Usage

CLLocationCoordinate2D coordinate = NSTimeZone.localTimeZone.coordinate;

NSLog(@"%@: %f, %f", NSTimeZone.localTimeZone, coordinate.latitude, coordinate.longitude);
// → Local Time Zone (America/New_York (EDT) offset -14400 (Daylight)): 40.714000, -74.006000

To set the center coordinate of a map view (e.g., using the Mapbox iOS SDK):

CLLocationCoordinate2D coordinate = NSTimeZone.localTimeZone.coordinate;
if (CLLocationCoordinate2DIsValid(coordinate)) {
    [self.mapView setCenterCoordinate:coordinate];
}

Be sure to check that the returned coordinate is valid, as it is possible that this category may not find a coordinate for a given time zone.

See the demo project for more information about usage and available time zones.

Installation

Manual

Copy NSTimeZone+Coordinate.h/m and timezones.plist to your project. Make sure timezones.plist is bundled with your application.

Note: timezones.xml.plist is not used by this category — it exists so changes can be easily diffed.

CocoaPods

To integrate this category with CocoaPods, add this to your Podfile:

pod 'NSTimeZone-Coordinate'

Updating

  1. npm run update — updates the timezone submodule and regenerates the plists.
  2. Commit the new submodule commit hash and the changes to the binary and XML plist files.