我在使用Google地图和核心位置时遇到问题。 我有一个显示地图(使用谷歌地图)和当前位置(谷歌地图功能)的屏幕。 加载地图后,它会显示我的位置并显示位置指示器的使用(电池旁边的一个小箭头)。当我离开这个屏幕时,指示灯已经熄灭,有些则没有,也就是说,它仍在使用我的位置。
在上述情况下,当我将该位置用于另一个应用程序屏幕时,它会产生以下错误:
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
无论是否有互联网都会发生这种情况。从我观察到的就像谷歌地图继续使用我的位置。通常会发生此错误,但几秒钟后他会继续更新,但是当Google Maps发生错误时,它只会发布错误。并且在这一点上假定用户有权共享位置。
代码:
地图 - Google地图 - 今天更新的最新版本 - 10.14.2015
let coordinates = CLLocationCoordinate2DMake(-12.000000, -53.1805017)
let camera = GMSCameraPosition(target: coordinates, zoom: 3, bearing: 0, viewingAngle: 0)
self.map.delegate = self
self.map.camera = camera
self.map.myLocationEnabled = true
已经尝试在视图中设置myLocationEnabled false消失,但没有成功。
CLLocationManager
UIViewController
定义了CLLocationManagerDelegate
。
self.locationManager = CLLocationManager()
self.locationManager.startUpdatingLocation()
self.locationManager.delegate = self
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
委托方法:
// MARK: - CLLocationManagerDelegate
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let newLocation = locations.last
self.performGeocodeAddress(newLocation!)
self.locationManager.stopUpdatingLocation()
print("Location has updated")
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
NSLog("Error update location: \(error.description)")
self.locationManager.stopUpdatingLocation()
self.locationManager.startUpdatingLocation()
}