Skip to content

Locate the user of the current iOS device without CoreLocation.

License

Notifications You must be signed in to change notification settings

Tricertops/Where

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Where

Detect user’s location without Location Services. There are several ways to approximate user’s location and this little framework provides unified interface for all of them.

Created for this app: Geography of the World

Interface

There are two main methods on class Where:

  • Where.amI – where the user currently is.
  • Where.isHome – where the user is from.

Both of these return instance of Where class, which contains this info:

  • source – Value from enum with one of 6 sources.
  • timestamp – How old this instance is.
  • regionCode – 2-letter ISO 3166 code (US, GB, SK, JP).
  • regionName – English name of the region.
  • coordinate – Accuracy depends on source, typically it’s the middle of region.

Sources

  • Locale – Used to detect user’s residence, since that’s how you typically choose locale.
  • Carrier – Used to detect users’s residence, since carrier doesn’t change while roaming abroad.
  • Cellular IP – Similar to Carrier source, used to detect user’s residence.
  • Wi-Fi IP – When connected to Wi-Fi, external IP should tell us in which country is the user.
  • Time Zone – This is the most important source of location information. iOS uses Location Services when travelling to detect current time zone. This time zone is then available to apps and by checking tz database, we can get country and middle coordinate of the time zone. In addition, it’s instantly available (in contrast to Wi-Fi IP or Location Services).
  • Location Services – Finally, CoreLocation is integrated, but turned off by default. When enabled (see Options) it detects exact location, geocodes the region and then turns itself off.

To get latest instance for given source, call +[Where forSource:]

Options

You can customize behavior of the framework by calling +[Where detectWithOptions:] and passing one or more of these options:

  • UpdateContinuously – In addition to providing location once, the framework observes all sources and updates the detected location until cancelled. Notification WhereDidUpdateNotification is posted every time any source is updated. This is the default.
  • UseInternet – Enables use of Cellular IP and Wi-Fi IP sources.
  • UseLocationServices – Enables use of CoreLocation, implies UseInternet, because it needs geocoding.
  • AskForPermission – In addition to UseLocationServices (which it implies) also asks the user for permission to use CoreLocation. If you don’t pass this option, you have to gain permission yourself.

To turn off continuous updates or usage of internet, use option None.

Debugging

You can simulate user’s location by using -WhereDebug launch argument with ISO or time zone value.

Additions

Framework uses categories on NSLocale and NSTimeZone with some generaly useful methods:

  • Canonize region ISO codes to 2-letter uppercase form.
  • Lookup coordinates for region or time zone.
  • Get all time zones for given region.

Try

Project includes demo app Where Am I which demonstrates usage of all features. To see the framework in real app, check out Geography of the World app. Thanks.


The MIT License (MIT)
Copyright © 2015 Martin Kiss

About

Locate the user of the current iOS device without CoreLocation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published