Skip to content
프로젝트

fabiocaccamo/FCCurrentLocationGeocoder

GitHub에서 보기

소개

:iphone: :round_pushpin:  iOS geocoder for forward / reverse geocode user's current location using a block-based syntax.

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

FCCurrentLocationGeocoder Pod version Pod platforms Pod license

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

Installation

CocoaPods:

pod 'FCCurrentLocationGeocoder'

Manual install:

  • Copy FCCurrentLocationGeocoder.h and FCCurrentLocationGeocoder.m to your project
  • Manual install FCIPAddressGeocoder

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 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

Code sample

//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)
//check if location services are enabled and the current app is authorized or could be authorized
[geocoder canGeocode]; //returns YES or NO
//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'
    }
}];
//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'
    }
}];
//check if geocoding
[geocoder isGeocoding]; //returns YES or NO
//cancel geocoding
[geocoder cancelGeocode];

License

Released under MIT License.

관련 프로젝트 살펴보기

불러오는 중…