Objective c 如何在iOS 6中将步行轨迹或路线显示为地图覆盖

Objective c 如何在iOS 6中将步行轨迹或路线显示为地图覆盖,objective-c,ios,mapkit,mkoverlay,Objective C,Ios,Mapkit,Mkoverlay,我一直试图在互联网上搜索一个教程,其中包含一些示例代码,演示如何在地图上以覆盖的形式显示轨迹或路线。我找到了一些教程,但它们是用来显示圆和其他形状的。我想显示一个逐点轨迹 谁能给我一个好教程的链接,或者有人能给我指出正确的方向吗 任何帮助都将不胜感激 干杯尝试使用MKPolyline。您可以使用路线上每个转弯点的坐标创建一个CLLocation数组。使用该数组初始化MKPolyline对象。这将在指定的每个点之间绘制一条实线。如果点之间的距离足够远,需要拆分直线,则可以调整直线的dashPatt

我一直试图在互联网上搜索一个教程,其中包含一些示例代码,演示如何在地图上以覆盖的形式显示轨迹或路线。我找到了一些教程,但它们是用来显示圆和其他形状的。我想显示一个逐点轨迹

谁能给我一个好教程的链接,或者有人能给我指出正确的方向吗

任何帮助都将不胜感激


干杯

尝试使用MKPolyline。您可以使用路线上每个转弯点的坐标创建一个CLLocation数组。使用该数组初始化MKPolyline对象。这将在指定的每个点之间绘制一条实线。如果点之间的距离足够远,需要拆分直线,则可以调整直线的dashPattern和dashPhase

我从一个NSMutableLat数组开始,长点称为点:

NSMutableArray *currentPoint;
int count = [points count];
double lat, long;

CLLocationCoordinate2D unitPath[count];
for (NSInteger index = 0; index < count; index++)
{
    currentPoint = [points objectAtIndex:index];

    Lat = [[currentPoint objectAtIndex:ORDER_TARGLAT] doubleValue];
    Long = [[currentPoint objectAtIndex:ORDER_TARGLONG] doubleValue];
    CLLocation *pathPoint = [[CLLocation alloc] initWithLatitude:Lat longitude:Long];
    unitPath[index] = pathPoint.coordinate;
}

MKPolyline *routeLine = [MKPolyline polylineWithCoordinates:unitPath count:count];

routeLine.title = _title;
routeLine.subtitle = [[NSString alloc] initWithFormat:@"%d",ID];
routeLine.strokeColor = [UIColor whiteColor];
routeLine.fillColor = [UIColor whiteColor];
NSNumber *lineGapSize = [NSNumber numberWithInteger:10];
routeLine.dashPattern = [NSArray arrayWithObjects:lineGapSize,lineGapSize,nil];
routeLine.dashPhase = lineDashPhase;
routeLine.lineWidth = 4; 

[mapView addOverlay:routeLine]
NSMutableArray*currentPoint;
整数计数=[点数计数];
双板条,长;
CLLocationCoordinate2D单元路径[计数];
对于(NSInteger index=0;index

p.S.ORDER_TARGLAT和ORDER_TARGLONG只是指定项目在我的数组中位置的枚举的一部分。根据您的代码进行适当的替换。

尝试使用MKPolyline。您可以使用路线上每个转弯点的坐标创建一个CLLocation数组。使用该数组初始化MKPolyline对象。这将在指定的每个点之间绘制一条实线。如果点之间的距离足够远,需要拆分直线,则可以调整直线的dashPattern和dashPhase

我从一个NSMutableLat数组开始,长点称为点:

NSMutableArray *currentPoint;
int count = [points count];
double lat, long;

CLLocationCoordinate2D unitPath[count];
for (NSInteger index = 0; index < count; index++)
{
    currentPoint = [points objectAtIndex:index];

    Lat = [[currentPoint objectAtIndex:ORDER_TARGLAT] doubleValue];
    Long = [[currentPoint objectAtIndex:ORDER_TARGLONG] doubleValue];
    CLLocation *pathPoint = [[CLLocation alloc] initWithLatitude:Lat longitude:Long];
    unitPath[index] = pathPoint.coordinate;
}

MKPolyline *routeLine = [MKPolyline polylineWithCoordinates:unitPath count:count];

routeLine.title = _title;
routeLine.subtitle = [[NSString alloc] initWithFormat:@"%d",ID];
routeLine.strokeColor = [UIColor whiteColor];
routeLine.fillColor = [UIColor whiteColor];
NSNumber *lineGapSize = [NSNumber numberWithInteger:10];
routeLine.dashPattern = [NSArray arrayWithObjects:lineGapSize,lineGapSize,nil];
routeLine.dashPhase = lineDashPhase;
routeLine.lineWidth = 4; 

[mapView addOverlay:routeLine]
NSMutableArray*currentPoint;
整数计数=[点数计数];
双板条,长;
CLLocationCoordinate2D单元路径[计数];
对于(NSInteger index=0;index

p.S.ORDER_TARGLAT和ORDER_TARGLONG只是指定项目在我的数组中位置的枚举的一部分。根据您的代码进行适当的替换。

苹果面包屑演示应用程序中显示了推荐方式。

苹果面包屑演示应用程序中显示了推荐方式

MapView* mapView = [[[MapView alloc] initWithFrame:
                         CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)] autorelease];

[self.view addSubview:mapView];

Place* home = [[[Place alloc] init] autorelease];
home.name = @"Home";
home.description = @"Sweet home";
home.latitude = 29.860323999999990000;
home.longitude =77.893305000000050000;

Place* office = [[[Place alloc] init] autorelease];
office.name = @"Office";
office.description = @"Bad office";
office.latitude = 28.644251400000000000;
office.longitude = 77.121190500000010000;

[mapView showRouteFrom:home to:office];
在ios 7.0中使用这个

在ios 7.0中使用这个