ios - 如何显示仅连接 2 个点的多段线?

标签 ios swift google-maps google-polyline

我正在使用 iOS Google Maps API 来显示 map 。我想在特定经度处添加一条线,以便用户可以知道该经度在哪里。

这是我试过的:

let path = GMSMutablePath()
path.add(CLLocationCoordinate2D(latitude: -90, longitude: -122))
path.add(CLLocationCoordinate2D(latitude: 90, longitude: -122))
polyline = GMSPolyline(path: path)
polyline.geodesic = true
polyline.strokeColor = .red
polyline.strokeWidth = 20 // I have set this to a big number to guarantee that my poor eyesight can see the line
polyline.map = mapView

我在任何地方都看不到这条线!

作为对照实验,我复制了从 tutorial 中绘制矩形的代码并将其粘贴在上面的代码之后:

let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))

// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.2);
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.map = mapView

它显示了矩形:

enter image description here

由于我绘制线条的代码紧接在绘制矩形的代码上方,因此我的代码也应该被执行。它应该画一条与矩形相接的线,从北极延伸到南极。但是为什么没有这条线呢?

最佳答案

问题是你的两个点不仅仅是任意两个点,它们之间也不仅仅是一条最短的线。

点(90, X) 和(-90, X) 无论X 的值如何,都是北极和南极,并且有无穷无尽的直线连接它们。我建议在其他两点之间添加赤道上的点 (0, X)。

I added a point on the equator between the north pole and south pole and now it only drew a line to the equator.

我无法解释。似乎是一个错误。尝试接近极点的值,例如 89-8989.999-89.999

关于ios - 如何显示仅连接 2 个点的多段线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53570284/

相关文章:

ios - WatchKit,我应该从 ExtensionDelegate 更新 UI 吗?

ios - 使用分发临时设置配置文件时未收到推送通知

iOS 崩溃符号

javascript - 使用外部按钮控制缩放级别

javascript - 在 Google map 上显示路径时出现问题

javascript - 如何将数据库值获取到javascript谷歌地图

ios - react native iOS : Launch Screen used instead of Launch Image in build

javascript - 使用 PhoneGap/jQuery Mobile 以编程方式在 iPhone/Android 日历中添加事件?

Swift 将协议(protocol)变量传递给泛型函数

ios - 如何快速比较枚举?