I Have written the below code for example:
But i an directed to always to my current location. How can i solve this issue ?
MapViewController *mvc = [[MapViewController alloc] initWithNibName:#"MapViewController" bundle:nil];
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = 47.640071;
annotationCoord.longitude = -122.129598;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = #"Microsoft";
annotationPoint.subtitle = #"Microsoft's headquarters";
[mvc.mapView addAnnotation:annotationPoint];
NOTE:
MapViewcontroller.h
#interface MapViewController : UIViewController <MKMapViewDelegate>
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#end
MapViewController.m
#implementation MapViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.mapView.delegate = self;
self.mapView.mapType = MKMapTypeStandard;
self.mapView.showsUserLocation = YES;
}
Try this on below of your code
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(annotationCoord, 200, 200)];
[mapView setRegion:adjustedRegion animated:YES];
May be help full.. Cheers ...
Related
I want to use my Pin (not default).
I tried above code. First, I can see default pin. When I touched showMyLocation, after I touched sightLocation, default pin change with my custom pin. I want to show my custom pin in first view.
TOCGSightAnnotation.h
#interface TOCGSightAnnotation : NSObject <MKAnnotation>
#property (strong, nonatomic) NSString *title;
#property (nonatomic,assign) CLLocationCoordinate2D coordinate;
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate title:(NSString *)title;
#end
TOCGSightAnnotation.m
#implementation TOCGSightAnnotation
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate title:(NSString *)title
{
if ((self = [super init])) {
self.coordinate =coordinate;
self.title = title;
}
return self;
}
#end
TOCGSightseeingMapKitViewController.h
#interface TOCGSightseeingMapKitViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
#property (strong) NSNumber *latitude;
#property (strong) NSNumber *longitude;
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#property (strong, nonatomic) CLLocationManager * locationManager;
#end
TOCGSightseeingMapKitViewController.m
#import "TOCGSightseeingMapKitViewController.h"
#import "TOCGSightAnnotation.h"
CLLocationCoordinate2D sightCoordinate;
MKCoordinateRegion region;
#interface TOCGSightseeingMapKitViewController ()
#end
#implementation TOCGSightseeingMapKitViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[self.locationManager startUpdatingLocation];
sightCoordinate = CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
TOCGSightAnnotation *annotation = [[TOCGSightAnnotation alloc] initWithCoordinate:sightCoordinate title:#"Sight Title"];
[self.mapView addAnnotation:annotation];
region =
MKCoordinateRegionMakeWithDistance(sightCoordinate, 500, 500);
[self.mapView setRegion:region animated:YES];
}
- (IBAction)myLocation:(id)sender
{
self.mapView.delegate = self;
self.mapView.showsUserLocation = YES;
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
}
- (IBAction)sightLocation:(id)sender
{
[self.mapView setRegion:region animated:YES];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[TOCGSightAnnotation class]])
{
MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView
dequeueReusableAnnotationViewWithIdentifier:#"CustomPinAnnotationView"];
if (!pinView)
{
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:#"CustomPinAnnotationView"];
pinView.image = [UIImage imageNamed:#"mapIcon.png"];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
}
else
pinView.annotation = annotation;
return pinView;
}
return nil;
}
The reason is simple. The method
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation
will get called only if you set the MKMapViewDelegate. As long as you didn't touch the button that calls the IBAction
- (IBAction)myLocation:(id)sender
the delegate is not set, so the delegate methods are not called. Try moving the line
self.mapView.delegate = self;
after your MKMapView allocation.
I tried this and it works.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[self.locationManager startUpdatingLocation];
}
- (void)viewDidAppear:(BOOL)animated
{
self.mapView.delegate = self;
sightCoordinate = CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
TOCGSightAnnotation *annotation = [[TOCGSightAnnotation alloc] initWithCoordinate:sightCoordinate title:#"Sight Title"];
[self.mapView addAnnotation:annotation];
region =
MKCoordinateRegionMakeWithDistance(sightCoordinate, 500, 500);
[self.mapView setRegion:region animated:YES];
}
When i compile and run my app the map view doesnt zoom to location as i though it would
.h file contains the following
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface myContactUsViewController : UIViewController
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#end
.m file contains the following
#import "myContactUsViewController.h"
#define METERS_PER_MILE 1609.344
#interface myContactUsViewController ()
#end
#implementation myContactUsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewWillAppear:(BOOL)animated {
// 1
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = 39.281516;
zoomLocation.longitude= -76.580806;
// 2
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
// 3
[_mapView setRegion:viewRegion animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = 39.281516;
zoomLocation.longitude= -76.580806;
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.18;
span.longitudeDelta=0.18;
region.span=span;
region.center= zoomLocation;
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];
I am working on an iOS application and want to include the Breadcrumb iOS Mapkit route functionality provided by apple as one of the feature. I have created a UIViewController in the storyboard (as a tab from a tab bar controller) and inserted a MKMapView in it. I have also connected it to the outlet in ThirdViewController shown below. The classes are shown below. I have classes CrumbPath and CrumbPathView exactly as in the Breadcrumb example at http://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html
Even with the same code, the mkoverlay route does not show in my app. Am I missing something important here. I am not experienced in iOS programming and may have missed something basic.
ThirdViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "CrumbPath.h"
#import "CrumbPathView.h"
#interface ThirdViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
{
#private
MKMapView *map;
CrumbPath *crumbs;
CrumbPathView *crumbView;
CLLocationManager *locationManager;
}
#property (nonatomic, retain) IBOutlet MKMapView *map;
#property (nonatomic, retain) CLLocationManager *locationManager;
#end
ThirdViewController.m
#import "ThirdViewController.h"
#interface ThirdViewController ()
#end
#implementation ThirdViewController
#synthesize locationManager, map;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.wantsFullScreenLayout = YES;
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
[self.view addSubview:self.map];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
self.map = nil;
self.locationManager.delegate = nil;
self.locationManager = nil;
}
-(void) dealloc
{
}
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark -
#pragma mark MapKit
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if(newLocation)
{
if((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) && (oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
{
if(!crumbs)
{
crumbs = [[CrumbPath alloc] initWithCenterCoordinate:newLocation.coordinate];
[map addOverlay:crumbs];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 2000, 2000);
[map setRegion:region animated:YES];
}
else
{
MKMapRect updateRect = [crumbs addCoordinate:newLocation.coordinate];
if(!MKMapRectIsNull(updateRect))
{
MKZoomScale currentZoomScale = (CGFloat)(map.bounds.size.width/map.visibleMapRect.size.width);
CGFloat lineWidth = MKRoadWidthAtZoomScale(currentZoomScale);
updateRect = MKMapRectInset(updateRect, -lineWidth, -lineWidth);
[crumbView setNeedsDisplayInMapRect:updateRect];
}
}
}
}
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if(!crumbView)
{
crumbView = [[CrumbPathView alloc] initWithOverlay:overlay];
}
return crumbView;
}
#end
You didn't have your ThirdViewController set as the delegate to your MKMapView in your storyboard, so mapView:viewForOverlay: was never being called. Setting the delegate property fixes the problem.
I just wanted to add a Polyline to my Map which is displayed in a tableviewcell. Unfortunately
the delegate methods are not called... Would be nice if someone knows why.
My tableview.h:
#import <UIKit/UIKit.h>
#import "Route.h"
#import <MapKit/MapKit.h>
#import <QuartzCore/QuartzCore.h>
#interface RoutesDetailView : UITableViewController<MKMapViewDelegate>{
Route *myRoute;
MKMapView *mapView;
// the view we create for the line on the map
MKPolylineView* _routeLineView;
// the rect that bounds the loaded points
MKMapRect _routeRect;
MKPolyline* _routeLine;
}
#property (nonatomic, retain) Route *myRoute;
#property (nonatomic,retain) MKMapView *mapView;
#property (nonatomic, retain) MKPolyline* routeLine;
#property (nonatomic, retain) MKPolylineView* routeLineView;
-(MKPolyline *) loadRoute: (Route *) theRoute;
#end
And my tableview.m:
#implementation RoutesDetailView
#synthesize myRoute,mapView;
#synthesize routeLine = _routeLine;
#synthesize routeLineView = _routeLineView;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
MKMapView *myMap = [[MKMapView alloc] initWithFrame:CGRectMake(10, 1, 300 , 300)];
myMap.layer.cornerRadius = 10.0;
[self setMapView:myMap];
[mapView setDelegate:self];
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = [[NSString stringWithFormat:#"%#",NSLocalizedString(#"DefaultPointLAT", nil)] doubleValue];
annotationCoord.longitude = [[NSString stringWithFormat:#"%#",NSLocalizedString(#"DefaultPointLONG", nil)] doubleValue];
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance (annotationPoint.coordinate,[[NSString stringWithFormat:#"%#",NSLocalizedString(#"DefaultCircle", nil)] doubleValue], [[NSString stringWithFormat:#"%#",NSLocalizedString(#"DefaultCircle", nil)] doubleValue]);
[mapView setRegion:region animated:NO];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
.
.
.
static NSString *CellIdentifier = #"CellMap";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[mapView setFrame:CGRectMake(10, 1, cell.frame.size.width-20 , cell.frame.size.height-1)];
[cell addSubview:mapView];
[mapView addOverlay:[self loadRoute:myRoute]];
return cell;
.
.
.
}
#pragma mark - Table view delegate
-(MKPolyline *) loadRoute: (Route *) theRoute
{
MKMapPoint northEastPoint;
MKMapPoint southWestPoint;
// create a c array of points.
MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * theRoute.latitude.count);
for(int idx = 0; idx < theRoute.latitude.count; idx++)
{
CLLocationDegrees latitude = [[[theRoute latitude] objectAtIndex:idx] doubleValue];
CLLocationDegrees longitude = [[[theRoute longitude] objectAtIndex:idx] doubleValue];
// create our coordinate and add it to the correct spot in the array
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
MKMapPoint point = MKMapPointForCoordinate(coordinate);
//
// adjust the bounding box
//
// if it is the first point, just use them, since we have nothing to compare to yet.
if (idx == 0) {
northEastPoint = point;
southWestPoint = point;
}
else
{
if (point.x > northEastPoint.x)
northEastPoint.x = point.x;
if(point.y > northEastPoint.y)
northEastPoint.y = point.y;
if (point.x < southWestPoint.x)
southWestPoint.x = point.x;
if (point.y < southWestPoint.y)
southWestPoint.y = point.y;
}
pointArr[idx] = point;
}
// create the polyline based on the array of points.
self.routeLine = [MKPolyline polylineWithPoints:pointArr count:theRoute.latitude.count];
_routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);
// clear the memory allocated earlier for the points
free(pointArr);
return self.routeLine;
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay
{
NSLog(#"DELEGATE CALL");
MKOverlayView* overlayView = nil;
if(overlay == self.routeLine)
{
//if we have not yet created an overlay view for this overlay, create it now.
if(nil == self.routeLineView)
{
self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 15;
}
overlayView = self.routeLineView;
}
return overlayView;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
#end
Try this, I was having the same issue. After trying many combinations this is the one which works.
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface MapViewController : UIViewController<MKMapViewDelegate> {
MKMapView *mapView;
}
and the implementation...
- (void)viewDidLoad {
[super viewDidLoad];
mapView = [[MKMapView alloc] initWithFrame: CGRectMakeFullScreenIphone];
mapView.delegate = self;
[mapView setMapType: MKMapTypeStandard];
[self.view addSubview: mapView];
MKCoordinateRegion newRegion;
// configure region...
[mapView setRegion:newRegion animated:YES];
CLLocationCoordinate2D coordinate;
//configure coordinate...
MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
[annotation setCoordinate:coordinate];
[annotation setTitle:#"TEST"];
[mapView addAnnotation:annotation];
}
The simple code above works fine and delegate's methods were called.
if you are running the application in simulator, then the
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay
this delegate method will not get called, you need to run it on iOS Device.
The first Meth is
mapView:regionDidChangeAnimated:
and the second is
mapView:didUpdateUserLocation:
Header File
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface ViewController : UIViewController <MKMapViewDelegate>
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#property (weak, nonatomic) IBOutlet UIButton *searchButton;
#end
Implementation File
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
self.mapView.mapType = MKMapTypeStandard;
self.mapView.showsUserLocation = YES;
self.searchButton.hidden = YES;
}
- (IBAction)setMapType:(UISegmentedControl *)sender {
switch (sender.selectedSegmentIndex) {
case 0:
self.mapView.mapType = MKMapTypeStandard;
break;
case 1:
self.mapView.mapType = MKMapTypeSatellite;
break;
case 2:
self.mapView.mapType = MKMapTypeHybrid;
break;
default:
break;
}
}
- (IBAction)zoomToCurrentLocation:(UIBarButtonItem *)sender {
float spanX = 0.00725;
float spanY = 0.00725;
MKCoordinateRegion region;
region.center.latitude = self.mapView.userLocation.coordinate.latitude;
region.center.longitude = self.mapView.userLocation.coordinate.longitude;
region.span.latitudeDelta = spanX;
region.span.longitudeDelta = spanY;
self.searchButton.hidden = YES;
[self.mapView setRegion:region animated:YES];
}
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
self.searchButton.hidden = NO;
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
[self.mapView setCenterCoordinate:userLocation.coordinate animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I'm having trouble changing the pinColor for an annotation in MapKit. When I don't try to implement the mapView:viewForAnnotation: method everything works (the annotation is added) but when I try to change the annotation view, the simulator crashes :
Here is the code :
MapViewController.h
#import "MapViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "Annotation.h"
#implementation MapViewController
#synthesize myMapView;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
CLLocationCoordinate2D location;
location.longitude = 2.21;
location.latitude = 48.5;
MKCoordinateSpan span;
span.latitudeDelta = 1*(1 - 0);
span.longitudeDelta = 1*(1 - 0);
MKCoordinateRegion region;
region.span = span;
region.center = location;
[myMapView setRegion:region animated:NO];
[myMapView regionThatFits:region];
Annotation *someAnnotation =[[Annotation alloc] init];
[myMapView addAnnotation:someAnnotation];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation {
MKPinAnnotationView *customPinview = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
customPinview.pinColor = MKPinAnnotationColorGreen;
customPinview.animatesDrop = YES;
customPinview.canShowCallout = YES;
return customPinview;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
MapViewController.m
//
// MapViewController.h
// TestMap
//
// Created by Johan Ismael on 10/21/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface MapViewController : UIViewController<MKMapViewDelegate> {
#private
IBOutlet MKMapView *myMapView;
}
#property (nonatomic, retain) IBOutlet MKMapView *myMapView;
//- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation;
#end
Thanks in advance !!!
Note : MapViewController is declared as the delegate of the MapView in IB
In the viewForAnnotation method, the alloc is being done on MKAnnotationView instead of MKPinAnnotationView. It must be crashing with "unrecognized selector" because MKAnnotationView doesn't have a pinColor property. Change the alloc to:
MKPinAnnotationView *customPinview = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:nil] autorelease];