Google Places Picker SDK(不起作用)Swift 4

时间:2018-12-13 14:37:29

标签: swift xcode google-maps sdk

我最近决定使用Google的Maps SDK来构建应用程序,但是问题是,当我打开视图控制器时,只允许我单击第一项。 我无法仅使用Google文档找到解决方案。 有人为此解决了吗?

import UIKit
import GoogleMaps
import GooglePlaces
import GooglePlacePicker

class PlacePickerVC: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate, GMSAutocompleteViewControllerDelegate, UITextFieldDelegate {

let currentLocationMarker = GMSMarker()
var locationManager = CLLocationManager()

var local = ""
var morada = ""

override func viewDidLoad() {
    super.viewDidLoad()
    self.title = "Teste"

    locationManager.delegate = self
    locationManager.requestWhenInUseAuthorization()
    locationManager.startUpdatingLocation()
    locationManager.startMonitoringSignificantLocationChanges()

    let config = GMSPlacePickerConfig(viewport: nil)
    let placePicker = GMSPlacePickerViewController(config: config)
    placePicker.delegate = self

    present(placePicker, animated: true, completion: nil)
}


// Handle the user's selection.
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
    //Display the places but only show
    print("Place name: \(place.name)")
    print("Place address: \(place.formattedAddress)")
    print("Place attributions: \(place.attributions)")
    dismiss(animated: true, completion: nil)
}

func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
    // TODO: handle the error.
    print("Error: ", error.localizedDescription)
}

// User canceled the operation.
func wasCancelled(_ viewController: GMSAutocompleteViewController) {
    dismiss(animated: true, completion: nil)
}

}

extension PlacePickerVC : GMSPlacePickerViewControllerDelegate {
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
    print("Place name \(place.name)")
}

func placePicker(_ viewController: GMSPlacePickerViewController, 
didFailWithError error: Error) {
    // In your own app you should handle this better, but for the demo we are just going to log
    // a message.
    NSLog("An error occurred while picking a place: \(error)")
}

func placePickerDidCancel(_ viewController: GMSPlacePickerViewController) {
    // Dismiss the place picker, as it cannot dismiss itself.
    //viewController.dismiss(animated: true, completion: nil)
    print("No place selected")
}
}

Numbers 1 2 and 3 can't be clicked.

0 个答案:

没有答案