現在位置の取得速度を上げたい
Bluetoothを使用したアプリを作成しています。
基本的にCoreBluetooth
を使用していますが、アプリ内で緯度・経度(のみ)を使用するために
CoreLocationのCLLocationCoordinate2D
で位置情報を取得しています。
アプリを起動した最初の画面で位置情報を取得しており、
取得した場合にはその画面に設置しているボタンがオン(isEnabled = true
)になるようにしています。
ただ、現状、現在地を取得するのに最低5秒前後、または5秒以上かかっています。
緯度・経度のみしか使用しないのですが、この取得時間を3秒前後くらいまでに速める方法はないでしょうか?
kCLLocationAccuracyBest
あたりは使用しておりません。
以下、CoreLocationで使用しているコードです。
import UIKit import CoreLocation class MainViewController: UIViewController, CLLocationManagerDelegate { var locationManager: CLLocationManager? override func viewDidLoad() { super.viewDidLoad() setUp() } func setUp() { locationManager = CLLocationManager() locationManager?.delegate = self locationManager?.requestLocation() } func startUpdating() { locationManager?.startUpdatingLocation() } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("error") } func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { if (status == .notDetermined) || (status == .restricted) || (status == .denied){ // Show dialog to ask user to allow getting location data locationManager?.requestWhenInUseAuthorization() } if !CLLocationManager.locationServicesEnabled() { return } } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let location:CLLocationCoordinate2D = manager.location!.coordinate // bluetoothService.lat = location.latitude // bluetoothService.lng = location.longitude } }
※補足
Xcode 11.3.1
target iOS12.0
です。
なにとぞ、ご教授お願い申し上げます。
追記
参考にした記事
いろんな記事をみていたのでこれらだけではありませんが..
パッと出てきたのがこれらだったので。。
回答1件
あなたの回答
tips
プレビュー