How to draw a line between two places in mapview on iphone?

- (MKOverlayView *)mapView:(MKMapView *)mapView12 viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineView *overlayView = nil;

    if (nil == overlayView) 
    {       
        overlayView = [[[MKPolylineView alloc] initWithOverlay:overlay] autorelease];

        overlayView.strokeColor = [UIColor blueColor];
        overlayView.lineWidth   = 5.0;  
    }

    return overlayView;
}
+3
source share
2 answers

I made an application on mapview. so if you want to get the right path, you need to use KMLViewer or use GoogleMaps. In google maps you can do this code

NSString * urlstring = [NSString stringWithFormat: @ "http://maps.google.com/?saddr=%f,%f&daddr=

% F% F ", sourcelocation.latitude, sourcelocation.longitude, destinationlocation.latitude, Destin

ationlocation.longitude];

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];
+1
source

I think you want to draw the right line between the stations, then use KMLparser for this.

use a subclass and then execute this method:

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    return [kml viewForOverlay:overlay];
}


 //  add the pin in mapview

    -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
    {
        return [kml viewForAnnotation:annotation];
    }
+1
source

All Articles