Draw poly line on the road in mkmap view - iphone

被刻印的时光 ゝ 提交于 2019-12-09 22:00:48

问题


i am making an navigation based application. In this application i am drawing a route from points selected by the user.

for Calculating the route i have used Google direction API. and for drawing the route i have used this code

- (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];


}

PROBLEM :~ When i am drawing a route i encountered a problem that it is not drawing polyline on the road. To explain this i have attached an image

as shown in the picture polyline is not on the road.

I have used UICGDirections but it is not working properly some times.

Please help me i am new to mapview.

Thanks in advance


回答1:


Below is a sample IPhone application demonstrates drawing routes on MKMapView using http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@ as URL

MapWithRoutes

You can take this as a reference as it has implemented the same thing what you are trying to achieve.



来源:https://stackoverflow.com/questions/15585711/draw-poly-line-on-the-road-in-mkmap-view-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!