简体   繁体   中英

App Crash in GMSPlace Picker while running on device.(iOS 8.3)

I'm using following code to pick location as suggested by 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")
            }
        })
    }

在此处输入图片说明 Issue with this code is its running perfectly on simulator but on device iOS 8.3 it crashes without giving any message

Change NSError to Error

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

Import these both in AppDelegate class

import GoogleMaps
import GooglePlaces

And, you need to set these both in didFinishLaunchingWithOptions

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

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

        return true
    }

I couldn't see the error message using device, only after i tested it in the simulator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM