Google Place Picker后更改View Controller

时间:2017-03-22 03:46:16

标签: swift xcode google-maps-api-3 gmsplacepicker

有人知道在Google Place Picker中选择一个地点而不是调用地点选择器的地方后如何转到其他视图控制器?

1 个答案:

答案 0 :(得分:0)

根据谷歌地方选择器documentation

@IBAction func pickPlace(_ sender: UIButton) {
  let config = GMSPlacePickerConfig(viewport: nil)
  let placePicker = GMSPlacePicker(config: config)

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

    if let place = place {
      DispatchQueue.main.async {
         //code to push or present a viewController
      }
    } else {
      print("No place selected")
      return
    }

    print("Place name \(place.name)")
    print("Place address \(place.formattedAddress)")
    print("Place attributions \(place.attributions)")
  })
}

希望这有帮助