在AppDelegate中,我有以下代码来支持位置跟踪:
let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()
locationManager.requestAlwaysAuthorization()在我的ViewController中,我发出了一个谷歌位置请求:
placesClient = GMSPlacesClient.shared()
placesClient.currentPlace(callback: { (placeLikelihoodList, error) -> Void in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
if let placeLikelihoodList = placeLikelihoodList {
let place = placeLikelihoodList.likelihoods.first?.place
if let place = place {
print("Place:\(place.name)")
}
}
})错误消息为:
0 "NSLocalizedFailureReason“:”Places接口找不到用户的位置,可能是因为用户不允许应用程序访问位置信息。“
发布于 2017-12-09 08:56:05
请确保将NSLocationWhenInUseUsageDescription密钥添加到Info.plist文件中。
<key>NSLocationWhenInUseUsageDescription</key>
<string>Show your location on the map</string>此外,为模拟器选择一个位置。转到您的模拟器,调试-> Location ->自定义位置
https://stackoverflow.com/questions/44484837
复制相似问题