我想在Google地图中添加和删除Marker
(pin)。当谷歌地图swift用户触摸屏时放下一个PIN
我想长时间放下引脚并将其删除。我想用它来选择我的目的地。我该怎么做?
let position = CLLocationCoordinate2DMake(10, 10)
let marker = GMSMarker(position: position)
marker.map = mapView
我想在Google地图中添加和删除Marker
(pin)。当谷歌地图swift用户触摸屏时放下一个PIN
我想长时间放下引脚并将其删除。我想用它来选择我的目的地。我该怎么做?
let position = CLLocationCoordinate2DMake(10, 10)
let marker = GMSMarker(position: position)
marker.map = mapView
此代码应该对您有所帮助!
//MARK: GMSMapViewDelegate Implimentation.
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)
{
plotMarker(AtCoordinate: CLLocationCoordinate2D.init(latitude: 17.432699, longitude: 78.374674),onMapView: mapView)
}
//MARK: Plot Marker Helper
private func plotMarker(AtCoordinate coordinate : CLLocationCoordinate2D, onMapView vwMap : GMSMapView) -> Void
{
let marker = GMSMarker(position: coordinate)
marker.map = vwMap
}
希望有帮助!
对于谁正在寻找使用斯威夫特一个完整的代码片段的那些:
GMSMapViewDelegate
@IBOutlet weak var googleMapView: GMSMapView!
的实例viewDidLoad()
GMSMapView中提到作为代表googleMapView.delegate = self
didTapAt
委托功能:func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D){ print("You tapped at \(coordinate.latitude), \(coordinate.longitude)") googleMapView.clear() // clearing Pin before adding new let marker = GMSMarker(position: coordinate) marker.map = googleMapView }