【问题标题】:Draw poly line on the road in mkmap view - iphone在 mkmapview 中绘制道路上的折线 - iphone
【发布时间】: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


【解决方案1】:

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

MapWithRoutes

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 2018-10-18
    • 1970-01-01
    • 2021-09-23
    • 2016-10-29
    • 2015-10-24
    相关资源
    最近更新 更多