I am using GoogleMaps and GooglePlaces APIs. I am trying to retrieve place details when I tap a marker. I understand I can retrieve place detail by using a placeID
, but how do I retrieve a PlaceID
in the first place? I have the coordinates of the place.
There is information on how to use a PlaceID
once we have it, but there isn't much information on how to retrieve a PlaceID
. I have place coordinate. Either I could use those coordinates directly to get details of the place or use it to get Place ID and then use the PlaceID to retrieve place Details.
Any ideas?
You can use the userData
section of the marker.
To define userData,
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let customData = customData(var123: "", var1234: 4, var12345: true)
marker.userData = customData
marker.map = self.mapView
}
To retrieve the information use,
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
print(marker.title)
// print marker userData
print(marker.userData)
print(CLLocation(latitude: marker.layer.latitude, longitude: marker.layer.longitude))
return true
}
Finally you can define the customData
class,
class customData{
var var1: String
var var2: Int
var var3: Bool
init(var123: String, var1234: Int, var12345: Bool) {
var1 = var123
var2 = var1234
var3 = var12345
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.