Hello,
I have an app where I put a custom overlay on a mapview (code below). I have 2 iphones to test on one with 5.0.1 and one with 5.1 and on the 5.1 device the overlay is causing a crash. Everything works fine till the moment when the image is supposed to be added.
I've tried pretty much everything and cant see what is wrong :-( The map is only loading properly when the images isnt added.
1) is anything wrong in my implementionen? Am I missing something? It works on my device with ios5.0.1 thou
2) has the implementation of overlays been adjusted in ios5.1?
3) Anyone else seen the same problem? I've another app build and relesed earlier and its based on the same solution. This app still works on the 5.1 device... can the compiler and the newer xcode version be the problem?
I would be very thankful for any hints on this issue... I have tried everything I could think of and really dont know where to look more :-(
Thanks in advance!
MACloop
This is my solution:
//call from viewcontroller with mapView
//and the delegate method in the same class:
//custom overlay
//custom overlayView
I have an app where I put a custom overlay on a mapview (code below). I have 2 iphones to test on one with 5.0.1 and one with 5.1 and on the 5.1 device the overlay is causing a crash. Everything works fine till the moment when the image is supposed to be added.
I've tried pretty much everything and cant see what is wrong :-( The map is only loading properly when the images isnt added.
1) is anything wrong in my implementionen? Am I missing something? It works on my device with ios5.0.1 thou
2) has the implementation of overlays been adjusted in ios5.1?
3) Anyone else seen the same problem? I've another app build and relesed earlier and its based on the same solution. This app still works on the 5.1 device... can the compiler and the newer xcode version be the problem?
I would be very thankful for any hints on this issue... I have tried everything I could think of and really dont know where to look more :-(
Thanks in advance!
MACloop
This is my solution:
//call from viewcontroller with mapView
Code:
...
CLLocationCoordinate2D lowerLeft = CLLocationCoordinate2DMake(south,west);
CLLocationCoordinate2D upperRight = CLLocationCoordinate2DMake(north,east);
CustomOverlay *co = [[CustomOverlay alloc]initWithLowerLeftCoordinate:lowerLeft withUpperRightCoordinate:upperRight];
[map addOverlay:co];
[co release];
//and the delegate method in the same class:
Code:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)oly{
CustomOverlay *c = (CustomOverlay *)oly;
CustomOverlayView* ov = [[CustomOverlayView alloc] initWithOverlay:c];
return [ov autorelease];
}
//custom overlay
Code:
- (id) initWithLowerLeftCoordinate:(CLLocationCoordinate2D)lowerLeftCoordinate withUpperRightCoordinate:(CLLocationCoordinate2D)upperRightCoordinate{
MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate);
MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate);
self.mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);
return self;
}
- (id)delegate {
return self.delegate;
}
- (void)setDelegate:(id <CustomOverlayDelegate>)newDelegate {
self.delegate = newDelegate;
}
- (CLLocationCoordinate2D)coordinate{
return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(self.mapRect), MKMapRectGetMidY(self.mapRect)));
}
- (MKMapRect)boundingMapRect{
return self.mapRect;
}
//custom overlayView
Code:
- (id)initWithOverlay:(id<CustomOverlayDelegate>) o {
self = [super initWithOverlay:o];
self.overlayToUse = o;
return self;
}
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
MKMapRect theMapRect = [self.overlayToUse boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
UIImage *image = [UIImage imageNamed:[self.overlayToUse overlay_image_path]];
UIGraphicsPushContext(context);
[image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:1.0];
UIGraphicsPopContext();
}
-(BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
return YES;
}