swift - How to add custom data to overlay in Google Maps for iOS? -
how can add custom data gmsgroundoverlay images in google maps ios? passing data on markers when clicked built-in "marker.userdata" ground overlays dont have property?
okay figured out if it's helpful else. not sure if best way this, works.
1.) extended gmsgroundoverlay class in map's main .swift file
extension gmsgroundoverlay { private struct customdata { static var userdata:any? = nil } var userdata:any? { { return customdata.userdata } set { customdata.userdata = newvalue } } }
2.) pass data on overlay before overlays added map
let overlaydata:[string:any] = ["id":id,"html":html,"picture":picture,"photos":photos] overlay.userdata = overlaydata
3.) receive data when overlays clicked
func mapview(_ mapview: gmsmapview, didtapoverlay overlay: gmsgroundoverlay) -> bool { print("# tapped overlay data: ") (key,value) in overlay.userdata as! [string:any] { print("# \(key) = \(value)") } return false }
Comments
Post a Comment