Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This seems to be a limitation of the MKMapView.</p> <p>A workaround is to split the +/-180 crossing into "east" and "west" parts.</p> <p>For an around-the-world trip (finish == start), you can put the "west" part of the crossing at the front of the polyline.<br> For example:</p> <pre><code>CLLocationCoordinate2D newYorkCoord = CLLocationCoordinate2DMake(40.7141667, -74.0063889); CLLocationCoordinate2D londonCoord = CLLocationCoordinate2DMake(51.5, -0.116667); CLLocationCoordinate2D japanCoord = CLLocationCoordinate2DMake(36, 138); CLLocationCoordinate2D sanFranciscoCoord = CLLocationCoordinate2DMake(37.775, -122.4183333); CLLocationCoordinate2D japanToSFMidpointEast; //use average calc as crude way to find midpoint... japanToSFMidpointEast.latitude = (japanCoord.latitude + sanFranciscoCoord.latitude)/2.0; japanToSFMidpointEast.longitude = 180; CLLocationCoordinate2D japanToSFMidpointWest; japanToSFMidpointWest.latitude = japanToSFMidpointEast.latitude; japanToSFMidpointWest.longitude = -180; int pointsCount = 6; CLLocationCoordinate2D *points = malloc(pointsCount * sizeof(CLLocationCoordinate2D)); points[0] = japanToSFMidpointWest; points[1] = sanFranciscoCoord; points[2] = newYorkCoord; points[3] = londonCoord; points[4] = japanCoord; points[5] = japanToSFMidpointEast; MKPolyline *polyline = [MKPolyline polylineWithCoordinates:points count:pointsCount]; [mapView addOverlay:polyline]; free(points); points = NULL; </code></pre> <p><br> If a trip is not around-the-world (finish != start), you'll have to use two polylines.<br> This example goes from Japan to SF:</p> <pre><code>CLLocationCoordinate2D japanCoord = CLLocationCoordinate2DMake(36, 138); CLLocationCoordinate2D sanFranciscoCoord = CLLocationCoordinate2DMake(37.775, -122.4183333); CLLocationCoordinate2D japanToSFMidpointEast; japanToSFMidpointEast.latitude = (japanCoord.latitude + sanFranciscoCoord.latitude)/2.0; japanToSFMidpointEast.longitude = 180; CLLocationCoordinate2D japanToSFMidpointWest; japanToSFMidpointWest.latitude = japanToSFMidpointEast.latitude; japanToSFMidpointWest.longitude = -180; int eastPointsCount = 2; CLLocationCoordinate2D *eastPoints = malloc(eastPointsCount * sizeof(CLLocationCoordinate2D)); eastPoints[0] = japanCoord; eastPoints[1] = japanToSFMidpointEast; MKPolyline *eastPolyline = [MKPolyline polylineWithCoordinates:eastPoints count:eastPointsCount]; [mapView addOverlay:eastPolyline]; free(eastPoints); eastPoints = NULL; int westPointsCount = 2; CLLocationCoordinate2D *westPoints = malloc(westPointsCount * sizeof(CLLocationCoordinate2D)); westPoints[0] = japanToSFMidpointWest; westPoints[1] = sanFranciscoCoord; MKPolyline *westPolyline = [MKPolyline polylineWithCoordinates:westPoints count:westPointsCount]; [mapView addOverlay:westPolyline]; free(westPoints); westPoints = NULL; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload