在评论中,您询问了如何取消选择当前选定的标记。这有点复杂。我是这样做的:
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
// `markers` is an array of all the markers currently on the map.
markers.forEach {
($0.iconView as! UIImageView).image = #imageLiteral(resourceName: "unselected-pin")
}
(marker.iconView as! UIImageView).image = #imageLiteral(resourceName: "selected-pin")
return true
}
先前的答案
func mapView(_ mapView: GMSMapView, didTapMarker marker: GMSMarker) -> Bool {
print("tapped on marker")
if storeMarker == marker {
(marker.iconView as! UIImageView).image = #imageLiteral(resourceName: "circleImage")
}
return true
}