How to: Display MKOverlay on MKMapView - ios

I need to display an MKOverlay on a map, but can't get it to actually appear.
I'm following the example from Apple's Location Awareness Programming Guide and the overlay wont display. Any help would be greatly appreciated, this is the first iPhone app I've made, so I might be missing something simple.
NavViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface NavViewController : UIViewController <MKMapViewDelegate> {
}
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#end
NavViewController.m
#import "MSUNavViewController.h"
#import <CoreLocation/CoreLocation.h>
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolygon class]])
{
MKPolygonView* aView = [[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay];
aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2];
aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7];
aView.lineWidth = 3;
return aView;
}
return nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Define an overlay that covers Colorado.
CLLocationCoordinate2D points[4];
points[0] = CLLocationCoordinate2DMake(41.000512, -109.050116);
points[1] = CLLocationCoordinate2DMake(41.002371, -102.052066);
points[2] = CLLocationCoordinate2DMake(36.993076, -102.041981);
points[3] = CLLocationCoordinate2DMake(36.99892, -109.045267);
MKPolygon* poly = [MKPolygon polygonWithCoordinates:points count:4];
poly.title = #"Colorado";
[_mapView addOverlay:poly];
}
Storyboard:
Any coding suggestions would be greatly appreciated.
Thanks!

Make sure to set mapView's delegate to the view controller instance( perhaps File's owner in this case).
In interface builder, right-click on the map view, drag from hollowed circle at the right of delegate, to the File's Owner icon at the Placeholder section in the pane on the left.
For storyboard, connect to the View Controller icon instead of File's Owner.

Probably you killing aView in - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay by return nil;
Try to add else before.
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolygon class]])
{
MKPolygonView* aView = [[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay];
aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2];
aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7];
aView.lineWidth = 3;
return aView;
}
else return nil;
}

Did you solve your problem? Just drag from the circle beside delegate (in your screen shot) to the circle which is the name of the class.. there is a setting in the inspector that would allow you to display where you are also..? You made need to centre the map in say viewDidLoad so it displays over Colorado..

Related

Custom annotation on MGLMapView (MapBox) in ios

I used MKMapView for drawing polyline and showing saved polyline and also custom annotations.
But now trying to replace MKMapView with MGLMapview.
Drawing ployline and showing default annotations successfully as shown in the previous MKMapView
But I stuck at how to show custom annotations like below.
Used JPSThumbnailAnnotation in MKMapView
My question is,
How can I show custom annotations like above image ?
Create your custom Annotaion class in .h file
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface LocationAnnotaion : NSObject<MKAnnotation>
#property NSString * titile;
#property (nonatomic, readonly)CLLocationCoordinate2D coordinate;
-(id)initWithTitile:(NSString*) titile AndCoOrdinate:(CLLocationCoordinate2D) locationCoordinate;
-(MKAnnotationView*)annotationView;
#end
im .m file write:
#implementation LocationAnnotaion
-(id)initWithTitile:(NSString *)titile AndCoOrdinate:(CLLocationCoordinate2D)locationCoordinate
{
if (self = [super init])
{
_titile = titile;
_coordinate= locationCoordinate;
}
return self;
}
-(MKAnnotationView*)annotationView
{
MKAnnotationView * annotationView = [[MKAnnotationView alloc]initWithAnnotation:self reuseIdentifier:#"LocationAnnotation"];
annotationView.enabled = YES;
// annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:#"location_sign_map"];
return annotationView;
}
#end
Add annotation to map view
LocationAnnotaion *annotation = [[LocationAnnotaion alloc]initWithTitile:LOCATION_TEXT AndCoOrdinate:your_coordinate];
[mapLocationView addAnnotation:annotation];
and in mapview delegate add
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[CCLocationAnnotaion class]])
{
CCLocationAnnotaion * myAnnotation = (CCLocationAnnotaion*)annotation;
MKAnnotationView * view = myAnnotation.annotationView;
view.centerOffset = CGPointMake(0, -view.image.size.height/2);
return view;
}
return nil;
}
Hope it will help .

how send Core Data object from MapView to DetailView

I have a list of gyms with all its properties in Core Data, I get this gyms with an NSFetchRequest and pass its to a NSArray, then with a For in and this array, I get to put the pins in the MapView, I do it with de next code (welcome suggestions for improvement this):
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
NSFetchRequest *reqInst = [NSFetchRequest fetchRequestWithEntityName:[KMTInstalacion entityName]];
reqInst.sortDescriptors = #[[NSSortDescriptor sortDescriptorWithKey:KMTInstalacionAttributes.tipoInstalacion_ES ascending:NO]];
KMTAppDelegate *appDelegate = (KMTAppDelegate *)[[UIApplication sharedApplication]delegate];
NSError *error;
NSArray *arrayInstalaciones = [appDelegate.model.context executeFetchRequest:reqInst error:&error];
NSLog(#"Las instalaciones encontradas en arrayInstalaciones son: %lu", (unsigned long)[arrayInstalaciones count]);
for (KMTInstalacion *todasInstalaciones in arrayInstalaciones) {
CLLocationCoordinate2D coordPunto1 = CLLocationCoordinate2DMake(todasInstalaciones.coorLatitudValue, todasInstalaciones.coorLongitudValue);
MKPointAnnotation *anotacion = [[MKPointAnnotation alloc]init];
[anotacion setCoordinate:coordPunto1];
[anotacion setTitle:todasInstalaciones.nombre_ES];
[anotacion setSubtitle:todasInstalaciones.direccion_ES];
[self.mapView addAnnotation:anotacion];
}}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:#"curr"];
pinView.animatesDrop = NO;
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pinView;
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
KMTMiAnotacion *anotacion = view.annotation;
KMTDetailVC *detalle = [[KMTDetailVC allc]init];
detalle.title = anotacion.title
detalle.nombreInstalacionSeleccionada = anotacion.instalacion;
[self performSegueWithIdentifier:#"deMapa" sender:self];
}
KMTMiAnotacion.h
#interface KMTMiAnotacion : NSObject <MKAnnotation>{
NSString *title;
NSString *subTitle;
KMTInstalacion *instalacion;
}
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *subTitle;
#property (nonatomic, copy) KMTInstalacion *instalacion;
#end
When I tap on one of the pinView shows me the name and address of the gym with the button to the right.
Now what I want is when you tap on the pinView button, take you to the DetailView view and send full gym object (KMTInstalacion) corresponding pinView you've pressed, not just the title or subtitle, since each gym has about 50 properties (photos, schedules, etc ...)
Any idea how to do this?
Make a property of the gym object in your DetailViewController's .h file. Also create a custom annotation (subclass of MKAnnotation) with the same property.
#property (nonatomic, strong) KMTInstalacion *gymObj;
When setting the annotation, assign the gymObj to it's property.
Then implement this delegate method of MKMapView in your Map Controllers .m file:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
YourAnnotation *annView = view.annotation;
detailedViewOfList *detailView = [[DetailedViewOfList alloc]init];
detailView.gymObj = annotation.gymObj;
// push view modally or, however you want
}
You can use below code for sample how u can send details to other view. As per your need you to send entire object to other view...!
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
annotation *annView = view.annotation;
DetailedViewController *detailVC = [[DetailedViewController alloc] initWithNibName:#"DetailedViewController" bundle:nil];
detailVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
detailVC.address = annView.address;
detailVC.name = annView.name;
[self presentModalViewController:detailVC animated:YES];
}
Hope it helps you..
First in your annotaion view delegat make a button to go in detail view like bellow:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *mypin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:#"current"];
mypin.pinColor = MKPinAnnotationColorPurple;
mypin.backgroundColor = [UIColor clearColor];
UIButton *goToDetail = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
mypin.rightCalloutAccessoryView = myBtn;
mypin.draggable = NO;
mypin.highlighted = YES;
mypin.animatesDrop = TRUE;
mypin.canShowCallout = YES;
return mypin;
}
Now use the following delegate whenever the button in annotationView will get tapped the following delegate will be called from where you can easly get which particular annotaion's button is tapped
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
annotation *annView = view.annotation;
detailedViewOfList *detailView = [[detailedViewOfList alloc]init];
detailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
detailView.address = annView.address;
detailView.phoneNumber = annView.phonenumber;
[self presentModalViewController:detailView animated:YES];
OR
[self.navigationController pushViewController:detailView animated:YES];
}
here annotaion is a class importing MKAnnotaion.h and address and phonenumber are properties of annotaion class you can make many more while the address and phoneNumber properties of detailView class are strong. So that you can pass values. Hope this will help you!

Resizing MKCircle on MKMapView is flickering

I'm trying to solve a problem since few days and I've got no good results. I've got a point and a circle on MKMapView. I've got UISlider and want to change size of MKCircle. Size is changed but during resizing this circle flickers and blinks.
Here is my code:
#implementation ViewController {
Annotation *_annotation;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_annotation = [[Annotation alloc] init];
[_annotation setCoordinate: CLLocationCoordinate2DMake(0, 0)];
[self.mapView addAnnotation:_annotation];
[self.mapView setCenterCoordinate:_annotation.coordinate animated:YES];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(_annotation.coordinate, 1000, 1000);
[self.mapView setRegion:region];
[self _addCircleOnCurrentLocationWithRadius:_slider.value];
}
- (IBAction)onSliderChanged:(UISlider *)sender {
[self.mapView removeOverlays:self.mapView.overlays];
[self _addCircleOnCurrentLocationWithRadius:sender.value];
}
- (void)_addCircleOnCurrentLocationWithRadius:(CGFloat)radius {
MKCircle *circle = [MKCircle circleWithCenterCoordinate:_annotation.coordinate radius:radius];
[self.mapView addOverlay:circle level:MKOverlayLevelAboveRoads];
}
#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKPinAnnotationView *view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"Annotation"];
return view;
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay {
MKCircleView *view = [[MKCircleView alloc] initWithCircle:overlay];
view.fillColor = [UIColor redColor];
view.strokeColor = [UIColor blueColor];
view.alpha = 0.3;
return view;
}
#end
I've tried:
removing old overlays and adding new one,
doing as above with NSOperationQueue
Here is a screen recording how it looks like.
I see that is possible to do, Apple did this in Reminders app.
Also I'm familiar with following topics:
Smooth resizing of MKCircle
Moving MKCircle on MKMapview and dragging MKMapview
Smooth resizing of MKCircle
Thank you in advance.
Edit
I've did it. I will add an answer with class which supports resizing today or tomorrow.
I've did it by creating subclass of MKCircleView and override - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)ctx method. TSCircleView class is shared on github here..

Callout opening wrong view after zoom in iOS7

Everything is working fine in my app except for one thing: after zooming in and zooming back out, to see the whole map, some callouts open the wrong detailview.
I don't know if I'm missing some code or else.
Using Xcode 5.1.1 for iOS7.
This is what I've got at the moment:
Annotation.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface Annotation: NSObject <MKAnnotation>
#property (nonatomic, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *subtitle;
#end
Annotation.m
#import "Annotation.h"
#implementation Annotation
#synthesize coordinate,title,subtitle;
#end
MapView.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface Nameofthemap : UIViewController <MKMapViewDelegate>
#property (strong, nonatomic) IBOutlet MKMapView *Nameofthemap;
#end
MapView.m
#import "MapView.h"
#import "Annotation.h"
#import "InfoViewController.h"
#import "InfoTwoViewController.h"
#interface MapView ()
#property (nonatomic, strong) IBOutlet InfoViewController *InfoViewController;
#property (nonatomic, strong) IBOutlet InfoTwoViewController *InfoTwoViewController;
#end
#define PLACE1_LATITUDE 43.777130;
#define PLACE2_LONGITUDE 10.790018;
#define PLACE2_LATITUDE 43.81471237;
#define PLACE2_LONGITUDE 10.67472765;
#implementation MapView
- (IBAction)changeMapType:(id)sender {
if (_MapView.mapType == MKMapTypeHybrid)
_MapView.mapType = MKMapTypeStandard;
else
_MapView.mapType = MKMapTypeHybrid;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self gotoLocation];
_MapView.showsUserLocation = YES;
}
- (void)gotoLocation
{
MKCoordinateRegion newRegion;
newRegion.center.latitude = PLACE1_LATITUDE;
newRegion.center.longitude = PLACE2_LONGITUDE;
newRegion.span.latitudeDelta = 0.25f;
newRegion.span.longitudeDelta = 0.25f;
[self.MapView setRegion:newRegion animated:YES];
NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
Annotation *myAnn;
Annotation *myAnn2;
//Place1 annotation
myAnn = [[Annotation alloc] init];
location.latitude = PLACE1_LATITUDE;
location.longitude = PLACE1_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = #"Name of the place";
myAnn.subtitle = #"Details";
[locations addObject:myAnn];
//Place2 annotation
myAnn2 = [[Annotation alloc] init];
location.latitude = PLACE2_LATITUDE;
location.longitude = PLACE2_LONGITUDE;
myAnn2.coordinate = location;
myAnn2.title = #"Name of place two";
myAnn2.subtitle = #"Details";
[locations addObject:myAnn2];
[self->_MapView addAnnotations:locations];
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)myAnn {
if ([myAnn isKindOfClass:[MKUserLocation class]])
{
((MKUserLocation *)myAnn).title = #"Your position";
return nil;
}
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:#"pinView"];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:myAnn reuseIdentifier:#"pinView"];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
if ([[myAnn title] isEqualToString:#"Name of the place"]){
[rightButton addTarget:self action:#selector(myAnnClicked:)forControlEvents:UIControlEventTouchUpInside];
}
if ([[myAnn title] isEqualToString:#"Name of place two"]){
[rightButton addTarget:self action:#selector(myAnn2Clicked:)forControlEvents:UIControlEventTouchUpInside];
}
pinView.rightCalloutAccessoryView = rightButton;
}
return pinView;
}
-(IBAction)myAnnClicked:(id)sender
{
InfoViewController *info = [[InfoViewController alloc]init];
[self.navigationController pushViewController:info animated:YES];
}
-(IBAction)myAnn2Clicked:(id)sender
{
InfoTwoController *info2 = [[InfoTwoController alloc]init];
[self.navigationController pushViewController:info2 animated:YES];
}
#end
It's an annotation view re-use issue.
In viewForAnnotation, the button targets are only being set when creating a view (if dequeueReusableAnnotationViewWithIdentifier returns nil).
But if dequeueReusableAnnotationViewWithIdentifier returns a previously-used view, the button target is still whatever was set for the annotation that used the view before.
That previous annotation may not be the same as the current annotation.
So it's possible for annotation "two" to re-use a view that was originally created for annotation "one" and tapping on the already-created button shows the info for "one" instead of "two".
To fix this, two things should be done:
If dequeueReusableAnnotationViewWithIdentifier returns a view (if pinView is not nil), the code must update the view's annotation property to the current annotation.
The button target must be set whether a new view is being created or a dequeued view is being re-used. The easiest way to do this is to move the button creation/setting after the main if and just before the return.
The updated viewForAnnotation would look like this:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)myAnn {
if ([myAnn isKindOfClass:[MKUserLocation class]])
{
((MKUserLocation *)myAnn).title = #"Your position";
return nil;
}
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:#"pinView"];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:myAnn reuseIdentifier:#"pinView"];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
}
else
{
//1. Re-using a view, update which annotation it's being used for now
pinView.annotation = myAnn;
}
//2. Now pinView is either a new view or re-used view.
//Set its button target based on current annotation...
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
if ([[myAnn title] isEqualToString:#"Name of the place"]){
[rightButton addTarget:self action:#selector(myAnnClicked:)forControlEvents:UIControlEventTouchUpInside];
}
if ([[myAnn title] isEqualToString:#"Name of place two"]){
[rightButton addTarget:self action:#selector(myAnn2Clicked:)forControlEvents:UIControlEventTouchUpInside];
}
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}
By the way, instead of creating separate methods for each annotation (which can get tedious), use the map view's calloutAccessoryControlTapped delegate method instead.
In fact, right now, the map view is calling both your custom methods and the calloutAccessoryControlTapped delegate method (in which there's no code currently).
In the delegate method, the annotation tapped is accessible via view.annotation.
So in viewForAnnotation, you would just do this:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)myAnn {
if ([myAnn isKindOfClass:[MKUserLocation class]])
{
((MKUserLocation *)myAnn).title = #"Your position";
return nil;
}
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:#"pinView"];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:myAnn reuseIdentifier:#"pinView"];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
else
{
pinView.annotation = myAnn;
}
return pinView;
}
Then in the calloutAccessoryControlTapped delegate method, you can do something like this:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
if ([view.annotation isKindOfClass:[Annotation class]])
{
Annotation *myAnn = (Annotation *)view.annotation;
id vcToPush = nil;
if ([[myAnn title] isEqualToString:#"Name of the place"]) {
vcToPush = [[InfoViewController alloc]init];
}
else if ([[myAnn title] isEqualToString:#"Name of place two"]) {
vcToPush = [[InfoTwoController alloc]init];
}
[self.navigationController pushViewController:vcToPush animated:YES];
}
}
Then remove the myAnnClicked and myAnn2Clicked methods.
You would also be much better off creating a generic "Info" view controller instead of a separate one for each annotation.
Some other unrelated things:
Don't put a semi-colon at the end of the #define lines
You've defined PLACE2_LONGITUDE twice
newRegion.center is using PLACE2_LONGITUDE instead of PLACE1_LONGITUDE

MKAnnotation goes out of mapview when dragging

I have a view with a little mapView inside. I have a custom annotationView to mark the user position. Everything works ok as usual but I've realize that the annotation is not clipped to the map view so, when I drag the map, it goes out of bounds. Check the pictures:
The mapView has the Clip Subviews enabled. I think this is the first time I found this behavior. Maybe I've never placed a map inside a bigger view with space around. I'm targeting iOS7 by the way.
EDIT: Here's the code. Nothing out of ordinary, I think.
Here, I add the custom annotation:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *const kAnnotationIdentifier = #"DYNAnnotationView";
DYNAnnotationView *annotationView = (DYNAnnotationView *)
[mapView dequeueReusableAnnotationViewWithIdentifier:kAnnotationIdentifier];
if (! annotationView)
{
annotationView = [[DYNAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kAnnotationIdentifier];
}
[annotationView setAnnotation:annotation];
return annotationView;
}
And here is the custom annotationView:
DYNAnnotation.h
#import <MapKit/MapKit.h>
#interface DYNAnnotationView : MKAnnotationView
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier;
#end
DYNAnnotation.m
#import "DYNAnnotationView.h"
#implementation DYNAnnotationView
-(id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self)
{
UIImage *image = [UIImage imageNamed:#"locationMark"];
CGRect frame = [self frame];
frame.size = [image size];
[self setFrame:frame];
[self setCenterOffset:CGPointMake(0.5f, 1.0f)];
[self setImage:image];
}
return self;
}
OK. The solution was easy after all. All I needed to do was embed the mapView inside another view and set its clip subview property to YES. Still don't understand why the map view doesn't take care of this.
Hope this help somebody.

Resources