ios - 在谷歌地图上难以获得 X 和 Y 中标记的位置?

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

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 委托(delegate)方法被调用,我想获得 x, y 值标记以创建一个 View ,该 View 说明该特定标记的某些信息。我该怎么做?

最佳答案

mapView:didTapMarker: 是一个在点击标记后调用的委托(delegate)函数。所以为了得到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
}

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

请参阅 didTap 的引用资料和 marker .

你可以通过Reverse Geocoding通过x和y的值得到marker的一些信息| .

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

关于ios - 在谷歌地图上难以获得 X 和 Y 中标记的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49893433/

相关文章:

javascript - 谷歌地图 - 未捕获的类型错误

ios - 如何在iOS中以编程方式设置UITableView背景颜色

ios - 从 xcode 中的特定点照亮旋转球体

ios - 未声明的类型 'NSPersistenContainer'

ios - NSInvalidArgumentException : Workout_Tracker. QuickAddViewController collectionView:numberOfItemsInSection:]:无法识别的选择器发送到实例

android - 放大时聚类标记不隐藏

iPhone KERN_INVALID_ADDRESS

ios - 使用较旧的 Xcode 项目时,屏幕尺寸打印出错误的分辨率

swift - 无法打开要在 YouTube tvOS 应用程序上播放的 YouTube URL

android - IllegalStateException 映射大小不应为 0