gpt4 book ai didi

ios - 在设备上运行时 GMSPlace Picker 中的应用程序崩溃。(iOS 8.3)

转载 作者:搜寻专家 更新时间:2023-11-01 05:38:03 24 4
gpt4 key购买 nike

我正在使用以下代码按照 Google 的建议选择位置

https://developers.google.com/places/ios-api/placepicker

    var placePicker: GMSPlacePicker?

override func viewDidLoad()
{
super.viewDidLoad()
self.pickPlace()
}

func pickPlace()
{
let center = CLLocationCoordinate2DMake(51.5108396, -0.0922251)
let northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001)
let southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001)
let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
let config = GMSPlacePickerConfig(viewport: viewport)
placePicker = GMSPlacePicker(config: config)

placePicker?.pickPlaceWithCallback({ (place: GMSPlace?, error: NSError?) -> Void in
if let error = error
{
print("Pick Place error: \(error.localizedDescription)")
return
}

if let place = place
{
print("Place name \(place.name)")
print("Place address \(place.formattedAddress)")
print("Place attributions \(place.attributions)")
self.navigationController?.popToRootViewControllerAnimated(true)


} else
{
print("No place selected")
}
})
}

enter image description here此代码的问题是它在模拟器上完美运行,但在设备 iOS 8.3 上它崩溃而没有给出任何消息

最佳答案

将 NSError 改成错误

placePicker?.pickPlaceWithCallback({ (place: GMSPlace?, error: Error?)

在 AppDelegate 类中导入这些

import GoogleMaps
import GooglePlaces

而且,你需要在 didFinishLaunchingWithOptions 中设置它们

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

GMSServices.provideAPIKey("Your key")
GMSPlacesClient.provideAPIKey("Your key")

return true
}

我在使用设备时看不到错误消息,只有在模拟器中测试后才能看到

关于ios - 在设备上运行时 GMSPlace Picker 中的应用程序崩溃。(iOS 8.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34509796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com