I'm fighting the hell with theses freaking polylines…
I still can't display it on my map !
I implemented :
NSArray *points = [NSArray arrayWithObjects:
[[CLLocation alloc] initWithLatitude:45.43894 longitude:-73.7396],
[[CLLocation alloc] initWithLatitude:45.44073 longitude:-73.73998],
// 72 more like that…
nil];
( Note that theses points are thoses used in the NVPolyline
depository on github.
First I tried to use theses classes but I couldn't display the polylines either… )
Then I do (like here):
int numPoints = [points count];
CLLocationCoordinate2D *arrayPtr = malloc(numPoints * sizeof(CLLocationCoordinate2D));
for(int i = 0; i<numPoints; i++) {
arrayPtr[i] = [[points objectAtIndex:i] coordinate];
}
polyline = [MKPolyline polylineWithCoordinates:arrayPtr count:numPoints];
[map addOverlay:polyline];
Instead of adding the polyline overlay, I also tried :
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:polyline];
[map addSubview:polylineView];
A priori, it should work because MKPolylineView
inherit from UIView
, but it crashes.
Here is the log :
-[CALayer levelsOfDetail]: unrecognized selector sent to instance 0x1d8319e0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayer levelsOfDetail]: unrecognized selector sent to instance 0x1d8319e0'
I have set my delegate through the storyboard, but I also tried to add [map setDelegate:self];
but nothing changes.
Where and why I'm wrong ?
Thanks for help and ideas.
EDIT, added :
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id < MKOverlay >)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]])
{
MKOverlayView *pView = [[MKOverlayView alloc] initWithOverlay:overlay];
return pView;
}
return nil;
}
Still doesn't work, I shall be idiot.
I also show you my .h : (seems correct for me)
@interface MapViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>
{
MKPolyline *polyline;
}
@property (weak, nonatomic) IBOutlet MKMapView *map;
@end