I am new to this so it may be that I'm missing something simple or whatever else.
Basically I want to draw a straight line from point to point, in my case I have all of my points in which each line should be drawn in an array of coordinates. And then I use overlay method to draw the line. And all of this in a MKMapView which I already defined and configured (Correctly).
So here is the code that I use to fill my array of coordinates and also create the overlay/polyline:
CLLocationCoordinate2D coordinateArray[arrayOfLatitudes.count];
for (int i = 0; i < arrayOfLatitudes.count; i++) {
double tempLatitude = [[arrayOfLatitudes objectAtIndex:(i)] doubleValue];
double tempLongitude = [[arrayOfLongitudes objectAtIndex:(i)] doubleValue];
coordinateArray[i] = CLLocationCoordinate2DMake(tempLatitude, tempLongitude);
}
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:arrayOfLatitudes.count];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
[self.mapView addOverlay:self.routeLine];
and this is my ViewForOverlay method which I asume configures my routeLine:
(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]])
{
MKPolylineView *mapOverlayView = [[MKPolylineView alloc] initWithPolyline:overlay];
//add autorelease if not using ARC
mapOverlayView.strokeColor = [UIColor redColor];
mapOverlayView.lineWidth = 3;
return mapOverlayView;
}
return nil;
}
I have these declarations in my .h as well:
@property (nonatomic, retain) MKPolyline *routeLine;
@property (nonatomic, retain) MKPolylineView *routeLineView;
I don't know why I can't see my routeLine drawn in my MapView, because I have used the exact logic(order of things) in another class and the lines appear with no problem.
What am I missing here? please help me
thanks in advance