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

  • Home
  • SEARCH
  • 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 4231614
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T01:59:29+00:00 2026-05-21T01:59:29+00:00

I thought this would be something that’s fairly common – but cant find it

  • 0

I thought this would be something that’s fairly common – but cant find it anywhere.
I know how to put images on a map. I use CSMapAnnotation found here http://spitzkoff.com/craig/?p=81.

I’ve pretty much taken the CSMapAnnotationTypeImage as an example and made a CSMapAnnotationTypeLabel but it keep just showing pins on the map and not the UILabel like I expected.

the header file

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>


@interface CSLabelAnnotationView : MKAnnotationView {
    UILabel* _label;
}
@property(retain, nonatomic)     UILabel* label;

@end

and the source file

#import "CSLabelAnnotationView.h"
#import "CSMapAnnotation.h"
#import "util.h"

@implementation CSLabelAnnotationView
@synthesize label = _label;

#define kWidth  120
#define kHeight 20

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    self.frame = CGRectMake(0, 0, kWidth, kHeight);
    self.backgroundColor = [UIColor clearColor];

    CSMapAnnotation* csAnnotation = (CSMapAnnotation*)annotation;   
    _label = [[UILabel alloc] initWithFrame:self.frame];
    _label.text=csAnnotation.title;
    [self addSubview:_label];
    return self;

}
#if 0
- (void)prepareForReuse
{
    TGLog(@"");
    [_imageView removeFromSuperview];
    [_imageView release];
}
#endif

-(void) dealloc
{
    [_label release];
    [super dealloc];
}
@end

to add it to the map

annotation = [[[CSMapAnnotation alloc] initWithCoordinate:coordinate
                                               annotationType:CSMapAnnotationTypeLabel
                                                        title:i.name
                                              reuseIdentifier:@"ocualabel"] autorelease];   
    [_mapView addAnnotation:annotation];

and

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKAnnotationView* annotationView = nil;

    if (annotation == mapView.userLocation){
        return nil; //default to blue dot
    }

    // determine the type of annotation, and produce the correct type of annotation view for it.
    CSMapAnnotation* csAnnotation = (CSMapAnnotation*)annotation;
    TGLog(@"csAnnotation.annotationType %d", csAnnotation.annotationType);
    if(csAnnotation.annotationType == CSMapAnnotationTypeStart || 
       csAnnotation.annotationType == CSMapAnnotationTypeEnd)
    {
        NSString* identifier = @"Pin";
        MKPinAnnotationView* pin = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if(nil == pin)
        {
            pin = [[[MKPinAnnotationView alloc] initWithAnnotation:csAnnotation reuseIdentifier:identifier] autorelease];
        }

        [pin setPinColor:(csAnnotation.annotationType == CSMapAnnotationTypeEnd) ? MKPinAnnotationColorRed : MKPinAnnotationColorGreen];

        annotationView = pin;
        TGLog(@"csPin anno");
    }
    else if(csAnnotation.annotationType == CSMapAnnotationTypeImage)
    {
        NSString* identifier = csAnnotation.reuseIdentifier;

        CSImageAnnotationView* imageAnnotationView = (CSImageAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
        if(nil == imageAnnotationView)
        {
            imageAnnotationView = [[[CSImageAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];   
            imageAnnotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        }
        TGLog(@"CSImage anno");
        annotationView = imageAnnotationView;
    } else if(csAnnotation.annotationType == CSMapAnnotationTypeLabel)
    {
        NSString* identifier = csAnnotation.reuseIdentifier;
        CSLabelAnnotationView* labelAnnotationView = (CSLabelAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
        if(nil == labelAnnotationView)
        {
            labelAnnotationView = [[[CSLabelAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];   
        }
        TGLog(@"CSLabel anno");

    } else {
        TGLog(@"%d", csAnnotation.annotationType);
    }
    [annotationView setEnabled:YES];
    [annotationView setCanShowCallout:YES];
    return annotationView;      
}

Can anyone help me with this? Or is there some other standard way to get UILabels on a map?

  • 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-21T01:59:30+00:00Added an answer on May 21, 2026 at 1:59 am

    Found it.
    Needed to add this in viewForAnnotation():

    annotationView = labelAnnotationView;
    
    • 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.