我正在制作一个基于导航的应用程序。在此应用程序中,我从用户选择的点绘制一条路线。
为了计算路线,我使用了Google Direction API
。为了绘制路线,我使用了这段代码
- (void) drawRoute:(NSArray *) path
{
NSInteger numberOfSteps = path.count;
[self.objMapView removeOverlays: self.objMapView.overlays];
CLLocationCoordinate2D coordinates[numberOfSteps];
for (NSInteger index = 0; index < numberOfSteps; index++)
{
CLLocation *location = [path objectAtIndex:index];
CLLocationCoordinate2D coordinate = location.coordinate;
coordinates[index] = coordinate;
}
for( id <MKOverlay> ovr in [self.objMapView overlays])
{
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:ovr];
if (polylineView.tag == 22)
{
[self.objMapView removeOverlay:ovr];
}
[polylineView release];
}
MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
[self.objMapView addOverlay:polyLine];
}
问题:~当我绘制路线时,我遇到了一个问题,即它没有在道路上绘制折线。为了解释这一点,我附上了一张图片
如图所示折线不在道路上。
我使用过UICGDirections
,但有时它无法正常工作。
请帮助我,我是 map View 新手。
提前致谢
最佳答案
下面是一个示例 iPhone 应用程序,演示了使用 http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@
作为 URL 在 MKMapView 上绘制路线
您可以将此作为引用,因为它实现了您想要实现的相同目标。
关于iphone - 在 mkmap View 中的道路上绘制折线 - iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15585711/