Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active December 28, 2018 01:22
Show Gist options
  • Save KentarouKanno/342bd82c030b730e0e3b to your computer and use it in GitHub Desktop.
Save KentarouKanno/342bd82c030b730e0e3b to your computer and use it in GitHub Desktop.
CLLocationManager

CLLocationManager

★ 初期化

let locationManager = CLLocationManager()

let locationManager: CLLocationManager = CLLocationManager()

★ Delegateの設定

locationManager.delegate = self

★ 領域監視を登録する

let coordinate = CLLocationCoordinate2DMake(location.latitude, location.longitude)
let region = CLCircularRegion(center: coordinate, radius: 200, identifier: location.pinTitle)
locationManager.startMonitoringForRegion(region)

★ 領域監視を登録した際に呼ばれるDelegate

func locationManager(manager: CLLocationManager, didStartMonitoringForRegion region: CLRegion) {
    print(region.identifier + "が登録されました")
}
// iOS8以降 info.plistに以下を記述する必要がある

// このApp使用中のみ許可を要求
<key>NSLocationWhenInUseUsageDescription</key>
<string>The spirit of stack overflow is coders helping coders</string>

//  常に許可を要求
<key>NSLocationAlwaysUsageDescription</key>
<string>I have learned more on stack overflow than anything else</string>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment