如何快速获取Google放置标记的纬度和经度

问题描述 投票:1回答:1

我试图从didTapAt获取标记位置,但是我没有获得地点ID后来我必须获取地方照片和地方细节。有什么办法可以从Google标记中获取确切的位置ID?

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
    print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
    mapView.camera = GMSCameraPosition.camera(withLatitude: coordinate.latitude, longitude: coordinate.longitude, zoom: 15)
}

var placesClient: GMSPlacesClient!
let fields: GMSPlaceField = GMSPlaceField(rawValue:UInt(GMSPlaceField.name.rawValue) |
        UInt(GMSPlaceField.placeID.rawValue) |
        UInt(GMSPlaceField.coordinate.rawValue) |
        GMSPlaceField.addressComponents.rawValue |
        GMSPlaceField.rating.rawValue |
        GMSPlaceField.photos.rawValue |
        GMSPlaceField.all.rawValue |
        GMSPlaceField.formattedAddress.rawValue)!

    placesClient?.fetchPlace(fromPlaceID: placeID, placeFields: fields, sessionToken: nil, callback: {
        (place: GMSPlace?, error: Error?) in
        if let error = error {
            print("An error occurred: \(error.localizedDescription)")
            self.stopActivityIndicator()
            return
        }
})

enter image description here

ios swift google-maps google-places
1个回答
0
投票

GMSMapViewDelegate]下,有一个功能可以监听兴趣点位置上的点击。功能func mapView(_ mapView: GMSMapView, didTapPOIWithPlaceID placeID: String, name: String, location: CLLocationCoordinate2D)返回位置信息以及地点标识符。

请参阅Google Maps iOS SDK文档中的以下example

© www.soinside.com 2019 - 2024. All rights reserved.