Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

swift

mapbox

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)
}

enter image description here

like image 356
user3556225 Avatar asked Oct 20 '25 11:10

user3556225


1 Answers

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.

like image 59
Magnas Avatar answered Oct 23 '25 01:10

Magnas