-1

I am new to mapview,i want to show current location of user and get direction into map in which i want to fix destination but source is not fix. I get the current location using CLLocation class. Now i want to fix destination and make it disable and not editable.

please give me some hints how to do this.

Thanks,

Nilam Pari
  • 331
  • 1
  • 3
  • 5

1 Answers1

0

First make your view controller implement the MKMapViewDelegate protocol and declare the properties you will need:

@property (nonatomic, retain) MKMapView *mapView; //this is your map view
@property (nonatomic, retain) MKPolyline *routeLine; //your line
@property (nonatomic, retain) MKPolylineView *routeLineView;

then in viewDidLoad (for example, or wherever you initialize)

//initialize your map view and add it to your view hierarchy - set its delegate to self*

CLLocationCoordinate2D coordinateArray[2];
coordinateArray[0] = CLLocationCoordinate2DMake(lat1, lon1); 
coordinateArray[1] = CLLocationCoordinate2DMake(lat2, lon2);


self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:2];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible

[self.mapView addOverlay:self.routeLine];

then implement the MKMapViewDelegate's method -(MKOverlayView *)mapView:viewForOverlay:

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
    if(overlay == self.routeLine)
    {
        if(nil == self.routeLineView)
        {
            self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
            self.routeLineView.fillColor = [UIColor redColor];
            self.routeLineView.strokeColor = [UIColor redColor];
            self.routeLineView.lineWidth = 5;

        }

        return self.routeLineView;
    }

    return nil;
}
Himanshu Moradiya
  • 4,769
  • 4
  • 25
  • 49