0

我想检索 MKPolyline,但我的代码不断返回 MKShape。我正在尝试使用此处描述的 GEOSwift 库: https ://github.com/GEOSwift/GEOSwift

我的代码:

let linestring = Geometry.create("LINESTRING(51.063164 -0.728986, 51.072347 -0.723721, 51.116898 -0.731893)")!
let shapeLine = linestring.mapShape()
self.mapView.add(shapeLine)

我收到错误:无法使用类型为“(MKShape)”的参数列表调用“添加”

(让 shapeLine = linestring.mapshape() 应该将其转换为 MKPolyline)

但是,如果我运行:

 let linestring = Geometry.create("LINESTRING(51.063164 -0.728986, 51.072347 -0.723721, 51.116898 -0.731893)")!
 let shapeLine = linestring.mapShape()
 dump(shapeLine)

我明白了:

- <MKPolyline: 0x60000069e550> #0
  - super: MKMultiPoint
    - super: MKShape
      - super: NSObject

这是说那里有一条折线吗?

我的叠加渲染器:

    func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    let renderer = MKPolylineRenderer(overlay: overlay)
    renderer.strokeColor = UIColor.blue
    renderer.lineWidth = 5.0

    return renderer
}

另外,我已经有其他折线在这个应用程序上工作。我已设置 MKMapViewDelegate 并将委托设置为 self。

///为了避免xy问题 - 我试图沿着一条路线搜索,所以我使用GEOSwift在折线周围创建缓冲区,然后使用它来搜索具有这些点的地理查询的数据库,下面是描述的具体问题在标题中:///

我确定错误很简单,但是我看了很长时间相同的代码,我只是看不到它。

任何帮助深表感谢

4

1 回答 1

0

mapShape()协议中定义的方法[GEOSwiftMapKit][1]返回 a MKShape,它是所有基于形状的 MapKit 覆盖对象的抽象基类。

该方法的实现将根据基础几何类型返回适当的子类,尽管正如我上面指出的,该方法的签名表明它返回的结果与's方法所期望的MKShape不符。MKOverlayMapKit.MapViewadd

所有你需要做的就是沮丧shapeLine到一个MKPolyline

guard let shapeLine = linestring.mapShape() as? MKPolyline else {
    preconditionFailure()
}
于 2017-11-20T12:09:40.303 回答