0

我一直在尝试在 Internet 上搜索带有一些示例代码的教程,该示例代码显示了如何在地图上将轨道或路线显示为叠加层。我找到了一些教程,但它们用于显示圆圈和其他形状。我想逐点显示轨迹。

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

任何帮助将不胜感激。

干杯

4

3 回答 3

3

推荐的方式显示在 Apples Breadcrumbs Demo App 中。

于 2013-04-25T10:34:18.910 回答
1

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

我从称为点的经纬度点的 NSMutableArray 开始:

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]

PS ORDER_TARGLAT 和 ORDER_TARGLONG 只是枚举的一部分,用于指定我的数组中项目的位置。根据您的代码替换。

于 2012-12-02T05:16:18.167 回答
1
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 中使用这个

于 2014-01-29T10:27:14.397 回答