【问题标题】:Having difficulty in getting the the position of markers in X and Y on google map?在谷歌地图上难以获得 X 和 Y 中标记的位置?
【发布时间】:2018-09-28 07:48:36
【问题描述】:
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 委托方法,我想获取标记的xy 值,以便创建一个视图,其中说明了一些信息特定的标记。我该怎么做?

【问题讨论】:

  • 你为什么不用info window
  • 如果您想将coordinates 转换为CGPoint,您可以使用var point = mapView.projection.point(for: marker.position)

标签: ios swift google-maps google-maps-markers


【解决方案1】:

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
}

请注意,标记具有“位置”属性,“位置”是坐标对。

请参阅didTapmarker 的参考资料。

您可以使用x和y的值来获取Reverse Geocoding标记的一些信息。

或者您可以使用info window 在您点击标记时向用户显示信息。

【讨论】:

    猜你喜欢
    • 2011-01-30
    • 2016-09-23
    • 2012-11-26
    • 2019-09-23
    • 2017-12-03
    • 1970-01-01
    • 2017-08-08
    • 2013-09-03
    • 1970-01-01
    相关资源
    最近更新 更多