通过一些在线帮助,我成功地在我的iOS应用程序中实现了一些Google地图功能。
extension GoogleMapViewController: GMSAutocompleteResultsViewControllerDelegate {
func resultsController(resultsController: GMSAutocompleteResultsViewController,
didAutocompleteWithPlace place: GMSPlace) {
searchController?.active = false
// Do something with the selected place.
print("Place name: ", place.name)
print("Place address: ", place.formattedAddress)
print("Place attributions: ", place.attributions)
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 6.0)
let mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
mapView.myLocationEnabled = true
view = mapView
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = place.formattedAddress
marker.map = mapView
}
}
我相信我已经从搜索栏中得到了
place.formattedAddress
,但我如何检索它的坐标,以便设置相机和标记来显示搜索的位置? 最佳答案
根据他们的documentation,您可以使用place.coordinate
let currentPlace: CLLocationCoordinate2D = place.coordinate
然后你可以得到它的纬度和经度分别为
currentPlace.latitude
和currentPlace.longitude
这是documentation