Ich versuche, eine Autocomplete-Box zu implementieren. In dieser App möchte ich die Entfernung mit einem Label auf der linken Seite in der Tabellenansicht zeigen. Ich nehme an, dass sie die Places Autocomplete-API verwenden, aber ich weiß nicht, dass sie die Entfernung auf der linken Seite in der Tabellenansicht anzeigt.wie man die Entfernung in Google Place Autocomplete zeigen iOS
extension ViewController: GMSAutocompleteResultsViewControllerDelegate {
func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
didAutocompleteWith place: GMSPlace) {
searchController?.isActive = false
// Do something with the selected place.
print("Place name: \(place.name)")
print("Place address: \(place.formattedAddress)")
print("Place attributions: \(place.attributions)")
self.googleMapsView.clear()
let position: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
let marker:GMSMarker = GMSMarker(position: position)
markerPosition = CLLocation(latitude: marker.position.latitude, longitude: marker.position.longitude)
marker.title = place.name
marker.appearAnimation = kGMSMarkerAnimationPop
marker.icon = GMSMarker.markerImage(with: .red)
marker.map = self.googleMapsView
self.googleMapsView.camera = GMSCameraPosition.camera(withLatitude: (place.coordinate.latitude), longitude: (place.coordinate.longitude), zoom: 17.0, bearing: 0, viewingAngle: 0)
searchController?.searchBar.text = place.name
self.dismiss(animated: true, completion: nil) // dismiss after select place
}
func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
didFailAutocompleteWithError error: Error){
// TODO: handle the error.
print("Error: ", error.localizedDescription)
}
}
Vielen Dank für die Antwort. Jetzt kann ich die Entfernung berechnen, aber ich kann die Entfernung nicht links in der Zelle Tableview anzeigen. – DoBeBee