シミュレータでDebug > Location > City Run を選択しても位置情報を出力しないのはなぜでしょうか?
ViewController.swiftは初期状態。
下記はLocationService.swiftに記述しているコードです。
このサイトを参考にしています。 位置情報を正確にトラッキングする技術 in iOS — (第2回)位置情報の取得
これはボクのXcodenoです
書いてるファイルが間違ってたりするかもしれないので、画像を載せてみました
ファイル名
現在のコード
Swift
1import UIKit 2import CoreLocation 3 4class LocationService: NSObject, CLLocationManagerDelegate { 5 6 let locationManager = CLLocationManager() 7 8 override init() { 9 10 locationManager.desiredAccuracy = kCLLocationAccuracyKilometer 11 locationManager.requestWhenInUseAuthorization() 12 13 super.init() 14 locationManager.delegate = self 15 locationManager.startUpdatingLocation() 16 } 17 18 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){ 19 20 if let newLocation = locations.last { 21 print("((newLocation.coordinate.latitude),(newLocation.coordinate.latitude))") 22 } 23 } 24}
最初のコード
Swift
1import Foundation 2import CoreLocation 3 4class LocationService:NSObject,CLLocationManagerDelegate { 5 6 override init() { 7 let locationManager = CLLocationManager() 8 locationManager.desiredAccuracy = kCLLocationAccuracyKilometer 9 locationManager.requestWhenInUseAuthorization() 10 11 super.init() 12 locationManager.delegate = self 13 14 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){ 15 16 if let newLocation = locations.last { 17 print("((newLocation.coordinate.latitude),(newLocation.coordinate.latitude))") 18 } 19 20 } 21 22 } 23 24} 25
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/26 07:20
2018/05/26 07:27 編集
2018/05/26 07:26
2018/05/26 07:28
2018/05/26 07:43
2018/05/26 07:55
2018/05/26 07:57