借助一些在线帮助,我成功地在iOS应用中实现了一些Google地图功能。Swift:Google Map API Camera和MapView
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
但如何取回其坐标,这样我可以设置相机和标记,以表明搜索到的地方吗?
我试图 “mapView.camera = GMSCameraPosition(目标:place.coordinate,缩放:15,轴承:0,viewingAngle:0)”,但它不工作。 – user6702783
'place.coordinate'返回一个'CLLocationCoordinate2D'。我已更新我的答案以反映 – eshirima
非常感谢。它现在工作! – user6702783