Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4586194
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:36:15+00:00 2026-05-21T21:36:15+00:00

please i have recently made a Map which suppose to show the user location

  • 0

please i have recently made a Map which suppose to show the user location (green pin color) and others annotations for service stations (red pins color), for the moment, i am able to show all annotations with the same color and i still unable to tell the MKMapView delegate how to make difference between two pin types and so assign to each type the right title to show.
this is my MKAnnotationView method :

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {

    static NSString *identifier = @"MyLocation";   
    if ([annotation isKindOfClass:[MyLocation class]]) {

        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        } else {
            annotationView.annotation = annotation;
        }

        annotationView.enabled = YES;
        [annotationView setAnimatesDrop:YES];
        annotationView.canShowCallout = YES;

               return annotationView;
    }

    return nil;    
}

and for my class which implement the MKAnnotation delegate i have this method :

-(id)initWithName:(NSString *)enseigneDeLaStation distanceVersLaStation:(NSString *) distanceVersLaStation coordinate:(CLLocationCoordinate2D)coordinate
{
    if ((self = [super init])) {
        _enseigneDeLaStation = [enseigneDeLaStation copy];
        _distanceVersLaStation = [distanceVersLaStation copy];
        _coordinate = coordinate;
    }
    return self;
}

thx in advance for your help 🙂

EDIT
i try to make the user location annotation like this, please if i am wrong correct me :

location2D = (CLLocationCoordinate2D){ .latitude = latitudeOfUserLocation, .longitude = longitudeOfUserLocation };
    MyLocation *annotation=[[[MyLocation alloc]initWithName:@"You are here" distanceVersLaStation:@"" coordinate:location2D]autorelease];
    [mapView addAnnotation:annotation];

EDIT 2
Hi again, i try to make one annotation to make sure it even call the annotation method so imake this simple example :

latitudeOfUserLocation=43.2923;
    longitudeOfUserLocation=5.45427;
    location2D = (CLLocationCoordinate2D){ .latitude = latitudeOfUserLocation, .longitude = longitudeOfUserLocation };
    MyLocation *annotation=[[[MyLocation alloc]initWithName:@"You are here" distanceVersLaStation:@"coucou" coordinate:location2D]autorelease];
    [mapView addAnnotation:annotation];

    MKCoordinateSpan span={latitudeDelta:1,longitudeDelta:0.5};
    MKCoordinateRegion region={location2D,span};
    [mapView setRegion:region];

when i run the app, i see the region zoomed well which go with the 43.2923/5.45427 but i don’t see the annotation, why it’s not calling the annotation method,i can’t move on since it’s not showing the user annotation, please help, thx in advance 🙂

EDIT 3
Hi, i assumed that this has always relation with making difference between user and station pins, so i have declared a var codeColor, set it to 1 (the type of the user) when invoking the annotations and set it to 2(station type) when calling the annotations for the stations :

-(void)viewWillAppear:(BOOL)animated
{  
       codeColor=1;//it's the first type, the user one
    MyLocation *annotation=[[[MyLocation alloc]initWithName:@"You are right here"   distanceVersLaStation:@"" coordinate:location2D]autorelease];
    annotation.pinColor = MKPinAnnotationColorGreen;  
    [mapView addAnnotation:annotation];

}

and :

-(void)requestFinished:(ASIHTTPRequest *)request
{  codeColor=2;
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    MyLocation *annotation=[[[MyLocation alloc]initWithName:ensStation distanceVersLaStation:distance coordinate:location2D]autorelease];
           annotation.pinColor = MKPinAnnotationColorPurple;  
           [mapView addAnnotation:annotation];


           }

and for the annotations method :

if (codeColor==2) {

            annotationView.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        }

now when testing for the first time, all is ok, the user annotation without button and the station one is with the button, but when i move from the view and i came back, all annotations are with buttons, even the user one. could you please help me there, thx in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:36:16+00:00Added an answer on May 21, 2026 at 9:36 pm

    One simple way is to add a pinColor property to your MyLocation class:

    @property (nonatomic, assign) MKPinAnnotationColor pinColor;
    

    When creating the annotation, set the pinColor:

    MyLocation *annotation=[[[MyLocation alloc]initWithName:@"You are here" distanceVersLaStation:@"" coordinate:location2D]autorelease];
    annotation.pinColor = MKPinAnnotationColorGreen;  //or red or whatever
    [mapView addAnnotation:annotation];
    

    and in the viewForAnnotation method:

    //...
    annotationView.canShowCallout = YES;
    annotationView.pinColor = ((MyLocation *)annotation).pinColor;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.