mapView viewForOverlay pas appelé
Bonjour à toutes et à tous,
J'essaye d'afficher un cercle sur ma map. Cependant, je n'arrive pas à appeler ma methode :
Code:
1 2
|
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay |
Celle ci devrait s'executer automatiquement mais rien ne se passe lorsque je debogue (je n'entre pas dans la fonction). Du coup pas de cercle!
Voici mon code dans le .m:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
//
// MapKitDisplayViewController.m
// MapKitDisplay
//
// Created by Chakra on 12/07/10.
// Copyright Chakra Interactive Pvt Ltd 2010. All rights reserved.
//
#import "MapKitDisplayViewController.h"
#import "DisplayMap.h"
@implementation MapKitDisplayViewController
@synthesize mapView;
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
MKCoordinateSpan span;
span.latitudeDelta = 0.01f;
span.longitudeDelta = 0.01f;
CLLocationCoordinate2D start;
start.latitude=22.569722;
start.longitude=88.369722;
MKCoordinateRegion region;
region.span = span;
region.center = start;
[mapView setRegion:region animated:YES];
/*
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center = location;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
*/
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = @" Kolkata";
ann.subtitle = @"Mahatma Gandhi Road";
ann.coordinate = region.center;
[mapView addAnnotation:ann];
double radius = 100.0;
MKCircle *circle = [MKCircle circleWithCenterCoordinate:start radius:radius ];
[mapView addOverlay:circle];
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[mapView release];
[super dealloc];
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]])
{
MKPolylineView *polylineView = [[[MKPolylineView alloc] initWithOverlay:overlay]autorelease];
polylineView.strokeColor = [UIColor redColor];
polylineView.lineWidth = 2.0;
return polylineView;
}
else if ([overlay isKindOfClass:[MKCircle class]])
{
MKCircleView *circleView = [[[MKCircleView alloc] initWithOverlay:overlay] autorelease];
circleView.strokeColor = [UIColor redColor];
circleView.lineWidth = 5.0;
circleView.fillColor = [UIColor colorWithRed:(255 / 255.0) green:(0 / 255.0) blue:(0 / 255.0) alpha:0.1];
return circleView;
}
return nil;
}
@end |
Quelqu'un connaitrait la raison? Sachant que ma map s'affiche ainsi que mon point!
Merci d'avance :)