通过点击,它使标记为无穷大。我想要一个标记,我点击了。再三,一而再再而三。没有很多标记。
我使用了MapView.clean()。但会删除所有标记。
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)
{
let marker = GMSMarker(position: coordinate)
marker.position.latitude = coordinate.latitude
marker.position.longitude = coordinate.longitude
print("hello")
print(markerr.position.latitude)
let ULlocation = markerr.position.latitude
let ULlgocation = markerr.position.longitude
print(ULlocation)
print(ULlgocation)
marker.map = self.mapView
}
答案 0 :(得分:0)
在didTapAt coordinate
方法之外创建标记,并在此方法中更改其坐标
class ViewController: UIViewController, GMSMapViewDelegate {
let marker = GMSMarker()
override func viewDidLoad() {
super.viewDidLoad()
marker.map = self.mapView
}
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)
{
marker.position = coordinate
}
}