我正在使用谷歌地图SDK与swift 3.我想获取当前位置的地图,但我无法获得当前位置的真实设备,但在模拟器,它显示了苹果的位置。但是在真实设备上,它显示了应用程序方案中的当前位置,否则显示错误“错误:错误域= kCLErrorDomain代码= 0”(空)“”。我使用下面的代码来获取当前location.Please帮助me.This代码在IOS 10,但在IOS 9使用谷歌地图获取ios 9中的当前位置sdk
@IBOutlet weak var view_map: GMSMapView!
let locationManager = CLLocationManager()
var didFindMyLocation = false
override func viewDidLoad() {
super.viewDidLoad()
view_map.isMyLocationEnabled = true
// //Location Manager code to fetch current location
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
if #available(iOS 9.0, *) {
locationManager.allowsBackgroundLocationUpdates = true
locationManager.requestLocation()
}
locationManager.startUpdatingLocation()
}
//Location Manager delegates
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let camera = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 17.0)
self.view_map.animate(to: camera)
//Finally stop updating location otherwise it will come again and again in this delegate
self.locationManager.stopUpdatingLocation()
}
// Handle authorization for the location manager.
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .restricted:
print("Location access was restricted.")
case .denied:
print("User denied access to location.")
// Display the map using the default location.
view_map.isHidden = false
case .notDetermined:
print("Location status not determined.")
case .authorizedAlways: fallthrough
case .authorizedWhenInUse:
print("Location status is OK.")
}
}
// Handle location manager errors.
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
locationManager.stopUpdatingLocation()
print("Error: \(error)")
}
相关不起作用:https://stackoverflow.com/questions/29312453/ ios-8-cant-get-current-location-error-domain-kclerrordomain-code-0 https://stackoverflow.com/questions/1409141/location-manager-error-kclerrordomain-error-0 https:// stackoverflow。 com/questions/32543754/ios-9-error-domain-kclerrordomain-code-0-null –
我会尝试所有,但不能解决我的问题 –
您是否检查了您的.plist中所需的密钥? –