Ответ 1
Чтобы получить координаты полилинии от MKRoute
, используйте метод getCoordinates:range:
.
Этот метод находится в классе MKMultiPoint
, который наследует MKPolyline
.
Это также означает, что это работает для любой полилинии - независимо от того, была ли она создана вами или с помощью MKDirections
.
Вы выделяете массив C, достаточно большой, чтобы удерживать нужное количество координат и указывать диапазон (например, все точки, начиная с 0-го).
Пример:
//route is the MKRoute in this example
//but the polyline can be any MKPolyline
NSUInteger pointCount = route.polyline.pointCount;
//allocate a C array to hold this many points/coordinates...
CLLocationCoordinate2D *routeCoordinates
= malloc(pointCount * sizeof(CLLocationCoordinate2D));
//get the coordinates (all of them)...
[route.polyline getCoordinates:routeCoordinates
range:NSMakeRange(0, pointCount)];
//this part just shows how to use the results...
NSLog(@"route pointCount = %d", pointCount);
for (int c=0; c < pointCount; c++)
{
NSLog(@"routeCoordinates[%d] = %f, %f",
c, routeCoordinates[c].latitude, routeCoordinates[c].longitude);
}
//free the memory used by the C array when done with it...
free(routeCoordinates);
В зависимости от маршрута будьте готовы к сотням или тысячам координат.