Problem With MapBox iOS MGLPolyline when crossing the (180 or -180) Longitude

旧城冷巷雨未停 提交于 2021-01-27 14:19:03

问题


in MapBox iOS sdk 4.4.1 if the MGLPolyline crosses the (180 or -180) Longitude , the map shows that it is going the longer way around the globe instead of going the shorter way.

    override func viewDidAppear(_ animated: Bool) {
    let points = [
        CLLocationCoordinate2D(latitude: 50.0, longitude: -170.0),
        CLLocationCoordinate2D(latitude: 50.0, longitude: 170),
                ]
    let line = MGLPolyline(coordinates: points, count: UInt(points.count))
    line.title = "line"
    mapView.addAnnotation(line)
}


回答1:


It makes sense that consecutive points are joined along lines of increasing latitude and/or longitude but default. Mapbox’s info regarding how to overcome this for MGLPolyline is found here.

The part of interest is: Mapbox MGLPolyline link

To make the polyline go across the antimeridian or international date line, specify some longitudes less than −180 degrees or greater than 180 degrees. For example, a polyline that stretches from Tokyo to San Francisco would have coordinates of (35.68476, -220.24257) and (37.78428, -122.41310).

So they're leaving it to the developer to implement their own logic to decide when and if it is appropriate to go the longer or shorter route.



来源:https://stackoverflow.com/questions/52584818/problem-with-mapbox-ios-mglpolyline-when-crossing-the-180-or-180-longitude

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!