vis*_*hnu 0 google-maps google-maps-markers ios swift
let camera = GMSCameraPosition.camera(withLatitude: 36.80, longitude: 10.18, zoom: 2.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.delegate = self
view = mapView
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: 36.80, longitude: 10.18)
marker.title = "Tunis"
marker.snippet = "Tunisia"
marker.map = mapView
let position = CLLocationCoordinate2D(latitude: 51.5, longitude: -0.127)
let london = GMSMarker(position: position)
london.title = "London"
london.map = mapView
Run Code Online (Sandbox Code Playgroud)
这是我的标志和点击它didtapMarker
委托方法被调用在我想x
,y
标志物的价值,以创建其中指出关于特定标记的一些信息视图.我怎样才能做到这一点?
mapView:didTapMarker:是一个在点击标记后调用的委托函数.因此,为了获得x和y的值,您需要这样做:
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
print(marker.position.latitude) //will print the x value or lat
print(marker.position.longitude) //will print the y value or lng
return false
}
Run Code Online (Sandbox Code Playgroud)
请注意,标记具有"位置"属性,"位置"是坐标对.
您可以使用x和y的值通过反向地理编码获取标记的一些信息.
或者,您可以使用信息窗口在点击标记时向用户显示信息.
归档时间: |
|
查看次数: |
195 次 |
最近记录: |