在谷歌文档文档中指定当前位置时,他们使用的是“默认location.coordinate”,我无法在我的代码中访问defaultLocation.coordinate。
以下是文档的链接:https://developers.google.com/maps/documentation/ios-sdk/current-place-tutorial
这是viewDidLoad中的代码
GMSServices.provideAPIKey("AIzaSyARsPfNs54hrUAC4yKtHeu2jXfGjeA0b-E")
GMSPlacesClient.provideAPIKey("AIzaSyARsPfNs54hrUAC4yKtHeu2jXfGjeA0b-E ")
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView
// creating the marker //
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView这是我的扩展代码
extension MapsViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location : CLLocation = locations.last!
print("Location:\(location)")
let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude, longitude: location.coordinate.longitude, zoom: zoomLevel)
if mapView.isHidden {
mapView.isHidden = false
mapView.camera = camera
}
else {
mapView.animate(to: camera)
}
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .restricted:
// display the map the default location
mapView.isHidden = false
case .denied :
print("User denied access to location")
mapView.isHidden = false
case .notDetermined :
print("Location status not deteremined")
case .authorizedAlways : fallthrough
case . authorizedWhenInUse :
print("Location status is OK")
}
}发布于 2019-01-27 02:54:22
我想您没有在Info.plist文件中添加密钥NSLocationWhenInUseUsageDescription。
然后,它应显示iOS系统弹出窗口,以允许位置访问。
发布于 2019-01-27 05:29:01
我已经阅读了你的问题,并检查了你给地图教程的链接。我发现您的viewDidLoad方法中缺少一些代码:
locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.distanceFilter = 50
locationManager.startUpdatingLocation()
locationManager.delegate = self
placesClient = GMSPlacesClient.shared()不像locationManager.delegate = self那样将委托赋给CLLocationManager的对象
我不认为你的分机会被称为(CLLocationManagerDelegate).
也叫
根据@Let's_Create的回答,info.plist应该有以下键来解释应用程序是如何使用它的。dataNSLocationAlwaysAndWhenInUseUsageDescription和NSLocationWhenInUseUsageDescription
https://stackoverflow.com/questions/54380215
复制相似问题