【发布时间】:2013-03-13 05:12:14
【问题描述】:
我正在制作一个基于导航的应用程序。在这个应用程序中,我从用户选择的点绘制路线。
为了计算我使用的路线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,但有时无法正常工作。
请帮助我,我是 mapview 的新手。
提前致谢
【问题讨论】:
-
我从here 得到了解决方案。我使用函数中给出的代码解析谷歌地图 API 给出的字符串。通过解析这些字符串,我得到了完美的折线
标签: iphone ios google-maps-api-3 mkmapview polyline