i'm having problem drawing mkpolylineview on mkmapview. line represents trip around world, begins , ends near new york, traveling east. 1 leg of trip, japan san francisco, crosses pacific ocean, , therefore longitude +/-180. mkpolylineview connect 2 points, travels in wrong direction. is, line travels west japan san francisco, instead of east across pacific. don't see option lets me specify direction line segment should travel connect 2 points.
to put simply, mkmapview doesn't seem understand world round. there way can draw line intended, traveling east japan san francisco?
i have screenshot displays problem clearly:
the polyline http://www.builtlight.org/pub/mkpolylineview.png
this seems limitation of mkmapview.
a workaround split +/-180 crossing "east" , "west" parts.
for around-the-world trip (finish == start), can put "west" part of crossing @ front of polyline.
example:
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 crude way 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;
if trip not around-the-world (finish != start), you'll have use 2 polylines.
example goes japan sf:
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;
Comments
Post a Comment