iphone - 在 mkmap View 中的道路上绘制折线 - iPhone

标签 iphone ios google-maps-api-3 mkmapview polyline

我正在制作一个基于导航的应用程序。在此应用程序中,我从用户选择的点绘制一条路线。

为了计算路线,我使用了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];


}

问题:~当我绘制路线时,我遇到了一个问题,即它没有在道路上绘制折线。为了解释这一点,我附上了一张图片

enter image description here

如图所示折线不在道路上。

我使用过UICGDirections,但有时它无法正常工作。

请帮助我,我是 map View 新手。

提前致谢

最佳答案

下面是一个示例 iPhone 应用程序,演示了使用 http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@ 作为 URL 在 MKMapView 上绘制路线

MapWithRoutes

您可以将此作为引用,因为它实现了您想要实现的相同目标。

关于iphone - 在 mkmap View 中的道路上绘制折线 - iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15585711/

相关文章:

iphone - 返回从 block 内部设置的 NSString

iphone - 如何隐藏一个iad

ios - removeObjectForKey 不会从 .plist 中删除值

ios - iOS 7 中导航栏的默认背景颜色是什么?

google-maps-api-3 - 动画后标记消失

ios - 管理您的应用安排的本地通知的好方法是什么?

iphone - 如何交换 NSMutableArray 中的值?

objective-c - dispatch_queue_t需要使用dispatch_release()来释放吗?

javascript - getRelevantGoogleReviews 不是 WordPress 中的函数错误,但可以在 Localhost 中使用

javascript - 带有 CSS 圆 Angular 的谷歌地图自定义标记