【问题标题】:mapbox direction api wrong route in iosios中的mapbox方向api错误路线
【发布时间】:2016-04-21 08:51:08
【问题描述】:

我正在使用 MapBox (Direction API) 在两点之间绘制路线。当我在 Mapbox 站点上的地图上绘制根时,我得到了正确的路线,但是当我在 iOS 上使用 MapboxDirection API (MapboxDirections.swift) 时,我得到了错误的路线(它只是缩短了路线而不是转弯。 网址:https://api.mapbox.com/v4/directions/mapbox.driving/58.3492489633563,37.898002422381;58.3578,37.8787.json?access_token=pk.****&alternatives=true&geometry=polyline

directions!.calculateDirectionsWithCompletionHandler { (response, error) in
                if let route = response?.routes.first {
                    print("Route summary:")
                    let steps = route.legs.first!.steps

                    print("Distance: \(route.distance) meters (\(steps.count) route steps) in \(route.expectedTravelTime / 60) minutes")
                    for step in steps {
                        print("\(step.instructions) \(step.distance) meters")

                        self.calculatedTour.append(step)
                        self.calculatedTourPoints.append(step.maneuverLocation)
                    }
                    self.tourLine = MGLPolyline(coordinates: &self.calculatedTourPoints, count: UInt(self.calculatedTour.count))

                    self.mapView.addAnnotation(self.tourLine)
                } else {
                    print("Error calculating directions: \(error)")
                }
            }

mapbox 网站:

在我的应用程序中:

【问题讨论】:

  • 我猜它是返回两个位置之间最短的路线?考虑汽车
  • 不,没有办法。
  • 问题解决了吗?我还有它
  • @TheRedFox 是的,我解决了。

标签: ios swift api mapbox


【解决方案1】:

这似乎是对路线的无意过度简化。

MapboxDirections.swift master 正确地渲染了这条路线,但是:

【讨论】:

  • 嗯,它可能正确地渲染了路线 - 更长的路线和更多的点将受到更多的简化。
  • 我在 mapbox 最新的 sdk 中遇到了这个问题,Directions 方法有时不会返回错误的路线
【解决方案2】:

问题已经解决

 for geoCoordinates in route.geometry {
       self.calculatedTourPoints.append(geoCoordinates)
   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2016-10-14
    • 1970-01-01
    • 2020-12-03
    相关资源
    最近更新 更多