Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabiocaccamo/fccurrentlocationgeocoder
:iphone: :round_pushpin: iOS geocoder for forward / reverse geocode user's current location using a block-based syntax.
https://github.com/fabiocaccamo/fccurrentlocationgeocoder
current-location geocode geocoder geocoding geoip ios ios-geocoder location objective-c pod reverse-geocoding
Last synced: 13 days ago
JSON representation
:iphone: :round_pushpin: iOS geocoder for forward / reverse geocode user's current location using a block-based syntax.
- Host: GitHub
- URL: https://github.com/fabiocaccamo/fccurrentlocationgeocoder
- Owner: fabiocaccamo
- License: mit
- Created: 2013-02-21T15:13:42.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-12-13T18:02:34.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T07:18:57.159Z (25 days ago)
- Topics: current-location, geocode, geocoder, geocoding, geoip, ios, ios-geocoder, location, objective-c, pod, reverse-geocoding
- Language: Objective-C
- Homepage:
- Size: 74.2 KB
- Stars: 261
- Watchers: 7
- Forks: 36
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
FCCurrentLocationGeocoder ![Pod version](http://img.shields.io/cocoapods/v/FCCurrentLocationGeocoder.svg) ![Pod platforms](http://img.shields.io/cocoapods/p/FCCurrentLocationGeocoder.svg) ![Pod license](http://img.shields.io/cocoapods/l/FCCurrentLocationGeocoder.svg)
=========================iOS Geocoder on top of LocationManager and CLGeocoder for **forward geocode and reverse geocode user's current location** using a block-based syntax.
It can also be used to **geocode the user's approximate location (always country, almost always city) without asking for permission** (using a free GeoIP service).
## Requirements & Dependecies
- iOS >= 5.0
- ARC enabled
- CoreLocation Framework
- [FCIPAddressGeocoder](https://github.com/fabiocaccamo/FCIPAddressGeocoder)## Installation
#### CocoaPods:
`pod 'FCCurrentLocationGeocoder'`#### Manual install:
- Copy `FCCurrentLocationGeocoder.h` and `FCCurrentLocationGeocoder.m` to your project
- Manual install [FCIPAddressGeocoder](https://github.com/fabiocaccamo/FCIPAddressGeocoder/#manual-install)## Usage
### iOS 8
Since iOS 8 it is required to add `NSLocationWhenInUseUsageDescription` key to your `Info.plist` file. Value for this key will be a description of UIAlertView presented to user while asking for location permission. See [Apple documentation](https://developer.apple.com/library/ios/documentation/corelocation/reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization) for more info.Basically all you need to do is to add single entry in your `Info.plist` file. Add key `NSLocationWhenInUseUsageDescription`, and select type `String`. The value you enter for this entry will be shown as text in UIAlertView presented to user first time you try to determine his location.
In the end it should look similar to this:![Added entry to Info.plist](https://raw.githubusercontent.com/burczyk/FCCurrentLocationGeocoder/ios8-location-permission/assets/Info_plist.png)
### Code sample
```objective-c
//you can use the shared instance
[FCCurrentLocationGeocoder sharedGeocoder];//you can also use as many shared instances as you need
[FCCurrentLocationGeocoder sharedGeocoderForKey:@"yourKey"];//or create a new geocoder and set options
FCCurrentLocationGeocoder *geocoder = [FCCurrentLocationGeocoder new];
geocoder.canPromptForAuthorization = NO; //(optional, default value is YES)
geocoder.canUseIPAddressAsFallback = YES; //(optional, default value is NO. very useful if you need just the approximate user location, such as current country, without asking for permission)
geocoder.timeFilter = 30; //(cache duration, optional, default value is 5 seconds)
geocoder.timeoutErrorDelay = 10; //(optional, default value is 15 seconds)```
```objective-c
//check if location services are enabled and the current app is authorized or could be authorized
[geocoder canGeocode]; //returns YES or NO
```
```objective-c
//current-location forward-geocoding
[geocoder geocode:^(BOOL success) {if(success)
{
//you can access the current location using 'geocoder.location'
}
else {
//you can debug what's going wrong using: 'geocoder.error'
}
}];
```
```objective-c
//current-location reverse-geocoding
[geocoder reverseGeocode:^(BOOL success) {if(success)
{
//you can access the current location using 'geocoder.location'
//you can access the current location placemarks using 'geocoder.locationPlacemarks'
//you can access the current location first-placemark using 'geocoder.locationPlacemark'
//you can access the current location country using 'geocoder.locationCountry'
//you can access the current location country-code using 'geocoder.locationCountryCode'
//you can access the current location city using 'geocoder.locationCity'
//you can access the current location zip-code using 'geocoder.locationZipCode'
//you can access the current location address using 'geocoder.locationAddress'
}
else {
//you can debug what's going wrong using: 'geocoder.error'
}
}];
```
```objective-c
//check if geocoding
[geocoder isGeocoding]; //returns YES or NO
```
```objective-c
//cancel geocoding
[geocoder cancelGeocode];
```## License
Released under [MIT License](LICENSE).