|
1 |
| -LocationManager |
2 |
| -=============== |
| 1 | +# INTULocationManager |
| 2 | +INTULocationManager makes it easy to get the device's current location on iOS. |
| 3 | + |
| 4 | +## What's wrong with CLLocationManager? |
| 5 | +CLLocationManager's API works well when you need to track changes in the user's location over time, such as for turn-by-turn GPS navigation apps. However, if you just need to ask "Where am I?" every now and then, CLLocationManager is fairly difficult to work with. |
| 6 | + |
| 7 | +Getting one-off location updates is a common task for many apps, such as when you want to autofill an address from the current location, or determine which city the user is currently in. Not only does INTULocationManager make this easy, but it also conserves the user's battery by powering down location services (e.g. GPS) as soon as they are no longer needed. |
| 8 | + |
| 9 | +## Usage |
| 10 | +To get the device's current location, use the method `requestLocationWithDesiredAccuracy:timeout:block:`. |
| 11 | + |
| 12 | +The `desiredAccuracy` specifies how **accurate and recent** of a location you need. The possible values are: |
| 13 | +```objective-c |
| 14 | +INTULocationAccuracyCity // 5000 meters or better, received within the last 10 minutes -- lowest accuracy |
| 15 | +INTULocationAccuracyNeighborhood // 1000 meters or better, received within the last 5 minutes |
| 16 | +INTULocationAccuracyBlock // 100 meters or better, received within the last 1 minute |
| 17 | +INTULocationAccuracyHouse // 15 meters or better, received within the last 15 seconds |
| 18 | +INTULocationAccuracyRoom // 5 meters or better, received within the last 5 seconds -- highest accuracy |
| 19 | +``` |
| 20 | + |
| 21 | +The `timeout` specifies how long you are willing to wait for a location with the accuracy you requested. The timeout guarantees that your block will execute within this period of time, either with a location of at least the accuracy you requested (`INTULocationStatusSuccess`), or with whatever location could be determined before the timeout interval was up (`INTULocationStatusTimedOut`). |
| 22 | + |
| 23 | +```objective-c |
| 24 | +INTULocationManager *locMgr = [INTULocationManager sharedInstance]; |
| 25 | +[locMgr requestLocationWithDesiredAccuracy:INTULocationAccuracyCity |
| 26 | + timeout:10.0 |
| 27 | + block:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) { |
| 28 | + if (status == INTULocationStatusSuccess) { |
| 29 | + // Request succeeded, meaning achievedAccuracy is at least the requested accuracy, and |
| 30 | + // currentLocation contains the device's current location. |
| 31 | + } |
| 32 | + else if (status == INTULocationStatusTimedOut) { |
| 33 | + // Wasn't able to locate the user with the requested accuracy within the timeout interval. |
| 34 | + // However, currentLocation contains the best location available (if any) as of right now, |
| 35 | + // and achievedAccuracy has info on the accuracy/recency of the location in currentLocation. |
| 36 | + } |
| 37 | + else { |
| 38 | + // An error occurred, more info is available by looking at the specific status returned. |
| 39 | + } |
| 40 | + }]; |
| 41 | +``` |
| 42 | +
|
| 43 | +When issuing a location request, you can optionally store the request ID, which allows you to force completion or cancel the request at any time: |
| 44 | +```objective-c |
| 45 | +NSInteger requestID = [[INTULocationManager sharedInstance] requestLocationWithDesiredAccuracy:INTULocationAccuracyHouse |
| 46 | + timeout:5.0 |
| 47 | + block:locationRequestBlock]; |
| 48 | +
|
| 49 | +// Force the request to complete early, like a manual timeout (will execute the block) |
| 50 | +[[INTULocationManager sharedInstance] forceCompleteLocationRequest:requestID]; |
| 51 | +
|
| 52 | +// Cancel the request (won't execute the block) |
| 53 | +[[INTULocationManager sharedInstance] cancelLocationRequest:requestID]; |
| 54 | +``` |
| 55 | + |
| 56 | +## Installation |
| 57 | +*INTULocationManager requires iOS 6.0 or later.* |
| 58 | + |
| 59 | +**Using [CocoaPods](http://cocoapods.org)** |
| 60 | + |
| 61 | +1. Add the pod `INTULocationManager` to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html). |
| 62 | + |
| 63 | + pod 'INTULocationManager' |
| 64 | + |
| 65 | +2. Run `pod install` from Terminal, then open your app's `.xcworkspace` file to launch Xcode. |
| 66 | +3. `#import INTULocationManager.h` wherever you want to use it. |
| 67 | + |
| 68 | +**Manually from GitHub** |
| 69 | + |
| 70 | +1. Download all the files in the [Source directory](https://github.com/intuit/LocationManager/tree/master/Source). |
| 71 | +2. Add all the files to your Xcode project (drag and drop is easiest). |
| 72 | +3. `#import INTULocationManager.h` wherever you want to use it. |
| 73 | + |
| 74 | +## License |
| 75 | +INTULocationManager is provided under the MIT license. |
0 commit comments