IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

XCode Discussion :

mapView viewForOverlay pas appelé [Objective-C]


Sujet :

XCode

  1. #1
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut 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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  2. #2
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    J'ai trouvé! L'erreur était assez bete! Il suffit d'ajouter cette ligne de code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    mapView.delegate = self;

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [débutant] la methode Validate() n'est pas appellée
    Par maxattack dans le forum Struts 1
    Réponses: 26
    Dernier message: 16/05/2007, 18h06
  2. destructeur pas appelé ?
    Par NiamorH dans le forum C++
    Réponses: 28
    Dernier message: 27/04/2007, 17h20
  3. [destructeur] [pas appelé]
    Par Gonath dans le forum C++
    Réponses: 11
    Dernier message: 23/02/2006, 19h37
  4. [servlet][filtre] filtre qui n'est pas appelé
    Par felix79 dans le forum Servlets/JSP
    Réponses: 4
    Dernier message: 29/06/2005, 21h09
  5. setTimeOut ne peu pas appeler une fonct. et appeler une var?
    Par bywazy dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 15/06/2005, 10h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo