【发布时间】:2018-10-26 05:30:33
【问题描述】:
晚上好,我正在尝试让用户在地图上定位自己。当我运行该应用程序并访问我的谷歌地图视图时,我收到错误消息“此应用程序已尝试在没有使用说明的情况下访问隐私敏感数据。应用程序的 Info.plist 必须包含一个“NSLocationWhenInUseUsageDescription”键和一个字符串值解释向用户展示应用程序如何使用这些数据”,并且地图被设置为默认状态。
我放了
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs your current location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs your current location</string>
在我的 info.plist 中,但它告诉我需要输入 NSLocationWhenInUseUsageDescription 才能访问位置。我已经把它放进去,它仍然不会显示用户位置!我是遗漏了什么还是这是一个错误?在我更新到最新版本的 Xcode 之前,它对我来说效果很好。
我启用谷歌地图的代码如下,
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
locationManager.delegate = self
locationManager.stopUpdatingLocation()
let location = locations.last
let lat = (location?.coordinate.latitude)!
let long = (location?.coordinate.longitude)!
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: long, zoom: 17.0)
self.myMapView.animate(to: camera)
showPartyMarkers(lat: lat, long: long)
}
func initGoogleMaps() {
let camera = GMSCameraPosition.camera(withLatitude: 40.014281, longitude: -83.030914, zoom: 17.0)
self.myMapView.camera = camera
self.myMapView.delegate = self
self.myMapView.isMyLocationEnabled = true
}
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
let lat = place.coordinate.latitude
let long = place.coordinate.longitude
showPartyMarkers(lat: lat, long: long)
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: long, zoom: 17.0)
myMapView.camera = camera
txtFieldSearch.text=place.formattedAddress
【问题讨论】:
-
你启动 CoreLocation 了吗?
-
@ktrkathi 我在我的导入中调用了它,但我从来没有为它编程过任何东西。我会提问以显示我的谷歌地图代码。
-
如果您使用模拟器。启用调试位置
-
@ktrkathir 我更新了上面的代码以展示我如何实现 gmaps
标签: swift xcode google-maps userlocation