难以获得 google 地图上 X 和 Y 中标记的位置?
Having difficulty in getting the the position of markers in X and Y on google map?
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
这些是我拥有的标记,点击它 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
}
注意marker有"position"属性,"position"是坐标对
您可以通过Reverse Geocoding.
使用x和y的值来获取marker的一些信息
或者您可以使用 info window 在您点击标记时向用户显示信息。
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
这些是我拥有的标记,点击它 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
}
注意marker有"position"属性,"position"是坐标对
您可以通过Reverse Geocoding.
使用x和y的值来获取marker的一些信息或者您可以使用 info window 在您点击标记时向用户显示信息。