【问题标题】:Convert the location on GMSMapView to the screen's coordinate system将 GMSMapView 上的位置转换为屏幕坐标系
【发布时间】:2017-08-03 09:45:04
【问题描述】:

我正在尝试将红色放置引脚的位置从 GMSMapView 转换为其父视图的坐标系(UIViewController 的视图)。

基本上,正如您从所附图片中看到的那样,图钉的位置相对于 GMSMapView 为 (170,275)。但是,我无法使用 GoogleMaps SDK 提供的功能来获得该值。

这是我尝试过的: 第 1 步,我有别针的 GPS 坐标,然后使用以下方法将其转换为 CGPoint:

let pinLocation = mapView.projection.point(for: pinCoordinate)

生成的 pinLocation 具有巨大的量级(例如:(1614979.75, -1187222.25)),与 mapView 中的可见 pin 不对应。 第二步,我在不同视图的坐标系之间转换点的位置:

let pinLocationInView = mapView.convert(pinLocation, to: view) // view contains the mapView

并且 pinLocationInView 的幅度几乎与 pinLocation 相同。显然,这种方法并没有像我预期的那样奏效。

然后,我尝试获取mapView投影的可见区域,希望通过简单的数学运算得到结果:

let region = projection.visibleRegion()
let farLeft = projection.point(for: region.farLeft)
let xOffset = pinLocation.x - farLeft.x
let yOffset = pinLocation.y - farLeft.y

令我惊讶的是,它也不起作用。原因是可见区域不是我在屏幕上实际看到的,farLeft是(0.0, 0.0)

在对适用于 iOS 的 GoogleMaps SDK 文档和本网站中的类似问题进行了大量研究后,我找不到任何问题的答案。

【问题讨论】:

  • 快速还是客观-?
  • Swift-3 和适用于 iOS 的 Google Maps SDK v2.3.3。
  • 你还需要这个答案吗?
  • @ReinierMelian 是的,我需要得到这个答案。可以指导一下吗?

标签: ios google-maps-sdk-ios coordinate-systems


【解决方案1】:

将 CGPoint 转换为经纬度

let topLeft = CGPoint(x: 0, y: 100)
let firstSideLatLong = mapView.projection.coordinate(for: topLeft)

将经纬度转换为 CGPoint

let coordinate = CLLocation(latitude:40.712216, longitude:-74.22655)
let point = mapView.projection.point(for: coordinate)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多