0

I'm using KML to show some overlays in map view. After parsing KML file I added overlay to my map view, but the map view delegate method viewForOverlay is not being called even if I set delegate property to map view.

What are the possible reasons for this problem?

NSURL *url = [NSURL fileURLWithPath:filePath];
kmlParser = [[KMLParser alloc] initWithURL:url];

[kmlParser parseKML];

// Add all of the MKOverlay objects parsed from the KML file to the map.
NSArray *overlays = [kmlParser overlays];
[self.mapView addOverlays:overlays];

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

I have done it using KMLViewer example.

smily
  • 357
  • 1
  • 7
  • 18
  • Show a few lines around where you call addOverlay and the viewForOverlay method. –  Aug 03 '12 at 13:49
  • Check that the `overlays` array is not empty (look at its `count`). –  Aug 03 '12 at 14:11
  • its not empty, one object is there – smily Aug 03 '12 at 14:19
  • 1
    What kind of overlay is it? Check that the overlay's coordinates and boundingMapRect are valid and in the place you expect (if the overlay is not supposed to be in view, the method won't get called). Try adding just a MKCircle using addOverlay and return a MKCircleView (set the fillColor) in viewForOverlay. Also make sure the map view's delegate method is being called or not by putting a breakpoint or NSLog in it (maybe it's the kmlParser's viewForOverlay method that's returning nil). –  Aug 03 '12 at 14:32
  • Thank you Karenina, your hint solved my problem, it works now... – smily Aug 06 '12 at 10:00

0 Answers0