Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-02-2009, 02:53 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Age: 27
Posts: 42
kiran.developer is on a distinguished road
Default How to add Title to the location

Hi,

I am getting a problem in Adding title to the location pin.Please tell me how to add the title.

Thanks
kiran.developer is offline   Reply With Quote
Old 05-14-2009, 08:23 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 100
varchar is on a distinguished road
Default

Quote:
Originally Posted by kiran.developer View Post
Hi,

I am getting a problem in Adding title to the location pin.Please tell me how to add the title.

Thanks

There are a few ways and general concepts to first understand:

1) the delegate viewForAnnotation gets called to draw pins
2) use MKAnnotation to set title/sub-title


Here is simple code:

Annotation.h

Code:

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


@interface Annotation : NSObject <MKAnnotation>{

	CLLocationCoordinate2D coordinate;
	
	NSString *currentSubTitle;
	NSString *currentTitle;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *currentTitle;
@property (nonatomic, retain) NSString *currentSubTitle;

- (NSString *)title;
- (NSString *)subtitle;

-(id)initWithCoordinate:(CLLocationCoordinate2D) c;


@end
Annotation.m

Code:

#import "Annotation.h"
#import <MapKit/MapKit.h>


@implementation Annotation

@synthesize coordinate;
@synthesize currentTitle;
@synthesize currentSubTitle;



- (NSString *)subtitle{
	return currentSubTitle;
}

- (NSString *)title{
//	NSLog(@"currenttitle: %@",currentTitle);
	return currentTitle;//  @"Marker Annotation";
}


-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
	coordinate=c;
	
	//NSLog(@"%f,%f",c.latitude,c.longitude);
	return self;
}
Now whereever you use the MKMapView (make sure to use the MKMapViewDelegate]

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

//	NSLog(@"Annotation called: %@",[annotation title]);
	MKPinAnnotationView *currentAnnotationView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"thisAnnotation"];
	MKPinAnnotationView *retval = nil;

	// If we have to, create a new view
	if (retval == nil) {
		retval = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"defaultpin"] autorelease];
		
		// Set up the Left callout
		UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
		myDetailButton.frame = CGRectMake(0, 0, 23, 23);
		myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
		myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
		
		// Set the image for the button
		[myDetailButton setImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
		[myDetailButton addTarget:self action:@selector(gotosomeaction:) forControlEvents:UIControlEventTouchUpInside]; 
		myDetailButton.tag  = [annotation title];
		
		// Set the button as the callout view
		retval.leftCalloutAccessoryView = myDetailButton;
		
	}

}
Hope the above helps...
varchar is offline   Reply With Quote
Old 05-15-2009, 01:37 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Age: 27
Posts: 42
kiran.developer is on a distinguished road
Default Thanks for the reply

it works
kiran.developer is offline   Reply With Quote
Old 05-27-2009, 02:44 PM   #4 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 28
Posts: 156
Narender Mudgal is on a distinguished road
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Default

Hi
Can i use MapKit framework for the applications based on 2.2.1 sdk, will it be acceptable or not by the apple, I am struggling for a lot of days . I am supposed to use same functionalities supported by 3.0 sdk mapkit framework , in 2.2.1 sdk. I have no idea how to show map like that and pop up for anotation. and screen redirection when click on that pop up. if i use this framework in my project will it be acceptable ????
Narender Mudgal is offline   Reply With Quote
Old 05-27-2009, 03:43 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 100
varchar is on a distinguished road
Default

Quote:
Originally Posted by Narender Mudgal View Post
Hi
Can i use MapKit framework for the applications based on 2.2.1 sdk, will it be acceptable or not by the apple, I am struggling for a lot of days . I am supposed to use same functionalities supported by 3.0 sdk mapkit framework , in 2.2.1 sdk. I have no idea how to show map like that and pop up for anotation. and screen redirection when click on that pop up. if i use this framework in my project will it be acceptable ????

I do not believe it will be accepted by Apple, since the MapKit is for OS 3.0. I am trying to figure out on my own when we can submit the apps based on 3.0 SDK. I would imagine it should be on the release of the OS, but would make sense that apple will allow it now...

Yet in my experiences, I see that Apple is already asking questions if the app has been testing on 3.0....
varchar is offline   Reply With Quote
Old 05-27-2009, 04:54 PM   #6 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 28
Posts: 156
Narender Mudgal is on a distinguished road
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Default Atleast any one replied

Hi varchar
Thank you very much for atleast replying,
I have seen some applications which are using same things in 2.0,
but how i dont understand. you can check myhomes application
my requirement is when i click on the marker it should show some image type of pop up with details. I am getting it but through javascripting . now i need when i click on that pop up my screen should be redirected to other screen by navigationController.pushviewcontroller , and i hope if i write this code in javascript it wont run and map will come blank. do you have any idea how to show objective c components when i click on marker in webview.
help will be highly appreciated. I am stucked here on this point. I have my deadline for day after tommorow
Narender Mudgal is offline   Reply With Quote
Old 05-27-2009, 04:55 PM   #7 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 28
Posts: 156
Narender Mudgal is on a distinguished road
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Question Atleast any one replied

Hi varchar
Thank you very much for atleast replying,
I have seen some applications which are using same things in 2.0,
but how i dont understand. you can check homes application(link is homes.com)
my requirement is when i click on the marker it should show some image type of pop up with details. I am getting it but through javascripting . now i need when i click on that pop up my screen should be redirected to other screen by navigationController.pushviewcontroller , and i hope if i write this code in javascript it wont run and map will come blank. do you have any idea how to show objective c components when i click on marker in webview.
help will be highly appreciated. I am stucked here on this point. I have my deadline for day after tommorow
Narender Mudgal is offline   Reply With Quote
Old 05-27-2009, 08:19 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 100
varchar is on a distinguished road
Default

Quote:
Originally Posted by Narender Mudgal View Post
Hi varchar
Thank you very much for atleast replying,
I have seen some applications which are using same things in 2.0,
but how i dont understand. you can check homes application(link is homes.com)
my requirement is when i click on the marker it should show some image type of pop up with details. I am getting it but through javascripting . now i need when i click on that pop up my screen should be redirected to other screen by navigationController.pushviewcontroller , and i hope if i write this code in javascript it wont run and map will come blank. do you have any idea how to show objective c components when i click on marker in webview.
help will be highly appreciated. I am stucked here on this point. I have my deadline for day after tommorow
Narender,

Interesting what you are trying to do, I literally wrote the code earlier today... I am at a client site now, but will return to my code base in a few hrs, then I will post the code for you which hopefully will help you....

In the meantime, some pointers:

First, I assume you are using the MKMapView class.

Then in the delegate:

Code:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
Make sure you build the MKAnnotationView which has the button in the leftaccessoryview.

Above maybe not make sense... I will just post code which will help.. give me a few hrs to get back.
varchar is offline   Reply With Quote
Old 05-27-2009, 09:23 PM   #9 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 28
Posts: 156
Narender Mudgal is on a distinguished road
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Smile Thanks a lot

Quote:
Originally Posted by varchar View Post
Narender,

Interesting what you are trying to do, I literally wrote the code earlier today... I am at a client site now, but will return to my code base in a few hrs, then I will post the code for you which hopefully will help you....

In the meantime, some pointers:

First, I assume you are using the MKMapView class.

Then in the delegate:

Code:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
Make sure you build the MKAnnotationView which has the button in the leftaccessoryview.

Above maybe not make sense... I will just post code which will help.. give me a few hrs to get back.
@Varchar
Thanks a lot man
i will be waiting for the post. i hope you are talking about the google code's mapview class. if it is like that i downloaded the code and try to understand how to implement it. but there is no documentation for that. well will continue after your post.
thanks dear.
Narender Mudgal is offline   Reply With Quote
Old 05-27-2009, 10:11 PM   #10 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 100
varchar is on a distinguished road
Default

Quote:
Originally Posted by Narender Mudgal View Post
@Varchar
Thanks a lot man
i will be waiting for the post. i hope you are talking about the google code's mapview class. if it is like that i downloaded the code and try to understand how to implement it. but there is no documentation for that. well will continue after your post.
thanks dear.
Narender,

I am not sure which code library you are referring to, but based on what I see you are trying to do, I suggest going with the iPhone SDK 3.0 MapView since it is quite easy to work with and very flexible.

Here is the code base and explanation on how to add button to callout.

Below is the method which handles drawing the view for the annotation depending on the type of annotation.

Code:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
	//NSLog(@"Annotation called: %@",[annotation title]);

	MKPinAnnotationView *currentLocationAnnotationPinView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"thisAnnotation"];
	MKAnnotationView *currentLocationAnnotationImageView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"thisAnnotation"];

	MKAnnotationView *currentMarkerAnnotationView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"thisAnnotation"];

	if([[annotation title] isEqualToString:@"Current Location"])
	 {
		 // Use a pin for current location - below is commented out since we do not want to use the pin, but our own custom image
		/* [currentLocationAnnotationPinView setPinColor:MKPinAnnotationColorPurple];
		 currentLocationAnnotationPinView.animatesDrop = YES;
		 return currentLocationAnnotationPinView;
		 */
		 
		 currentLocationAnnotationImageView.image = [UIImage imageNamed:@"Car.png"];
		 currentLocationAnnotationImageView.canShowCallout = YES;
		 return currentLocationAnnotationImageView;
		 
	 }
	else // Use a view for marker 
	{
	
		// Set up the Left callout
		UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
		myDetailButton.frame = CGRectMake(0, 0, 23, 23);
		myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
		myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
		
		// Set the image for the button
		[myDetailButton setImage:[UIImage imageNamed:@"favorites.png"] forState:UIControlStateNormal];
		
		
		// Set the button as the callout view
		currentMarkerAnnotationView.leftCalloutAccessoryView = myDetailButton;
		
		// Set the annotionview to an image
		currentMarkerAnnotationView.image = [UIImage imageNamed:@"favorites.png"];
		currentMarkerAnnotationView.canShowCallout = YES;
		return currentMarkerAnnotationView;
	
	
		
}

Below is the code which handles the tap on the button in the accessory annotation.

Code:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {


// DO SOMETHING.....
	
}
You see how easy the implementation is using the MKMapView classes using iPhone 3.0... its pretty cool.

Now, if you are unable to wait for the release (which is less then 2 weeks away), then you may want to use the RouteMe code library which is very handy and many of my apps use it...

Here is some code which handles taps and taps on labels...

Code:

- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map {

	NSLog(@"taponmarker");
	
	// Hide any markers which have been tapped before...
	for(RMMarker *marker in [map.markerManager getMarkers]) {
		[marker hideLabel];
	}
	
	// Show this current marker label
	[marker showLabel];
	
	
}



- (void) tapOnLabelForMarker: (RMMarker*) marker onMap: (RMMapView*) map {

	NSLog(@"taponlabelformarker clicked");
}

I hope the above will help you.... for the MKMapView code above you can literally do a copy and paste into your code and it should work.... Just wrote this code this morning...
varchar is offline   Reply With Quote
Old 05-27-2009, 10:22 PM   #11 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 28
Posts: 156
Narender Mudgal is on a distinguished road
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Smile

@varchar
Thank you very very much.
Its being a helping hand of you.
I am very thankful to you for sharing your code with me.
I will try it out and will be back to you once my code will work
or i have some problem
again thanks a ton to you.
Narender Mudgal is offline   Reply With Quote
Old 05-27-2009, 10:31 PM   #12 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 100
varchar is on a distinguished road
Default

Quote:
Originally Posted by Narender Mudgal View Post
@varchar
Thank you very very much.
Its being a helping hand of you.
I am very thankful to you for sharing your code with me.
I will try it out and will be back to you once my code will work
or i have some problem
again thanks a ton to you.

It's my pleasure.... That is one of the main purposes of this great forum we have here to help one another

Good luck and ping me if I can help in any other way....
varchar is offline   Reply With Quote
Old 05-28-2009, 12:16 AM   #13 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 28
Posts: 156
Narender Mudgal is on a distinguished road
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Question

@

Last edited by Narender Mudgal; 05-28-2009 at 09:39 PM.
Narender Mudgal is offline   Reply With Quote
Old 05-28-2009, 09:38 PM   #14 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 28
Posts: 156
Narender Mudgal is on a distinguished road
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Smile

Hi Varchar,
I am using route-me and able to show markers with pop up textlabel on it. but i wanted it to be some button or something not a simple label. i tried to put one btn inside one view and replace [marker setLabel:bView] and it is displaying it, but the problem is that is not excepting any touch event/click event. here is my code.

UIView *bView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitlebj_vendor.companyName forState:UIControlStateNormal];
btn.frame = CGRectMake(0, 0, 100, 30);
[bView addSubview:btn];
[marker setLabel:bView];

when ever i m clicking on this button in the log i can see is touch on map is detecting not on button. how could i do that.
Narender Mudgal is offline   Reply With Quote
Old 06-29-2009, 11:57 PM   #15 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 20
partha is on a distinguished road
Default

I implemented map view from mapkit(3.0) in my application it's working fine. But when ever i tap on pin my delegate method below i mentioned not at all calling. my map view class derived from UIView class, is this problem?.if any one reply as soon as possible.

- (void)mapViewMKMapView *)mapView annotationViewMKAnnotationView *)view calloutAccessoryControlTappedUIControl *)control {
partha is offline   Reply With Quote
Old 06-30-2009, 12:40 AM   #16 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 20
partha is on a distinguished road
Default MKMapViewDelegate method not calling when tap on pin

If i derived my map view class from UIViewcontroller class also delegate methos(mapView:annotationView:calloutAccessoryCont rolTapped not calling.
partha is offline   Reply With Quote
Old 07-28-2009, 07:32 PM   #17 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Australia
Posts: 180
svveet is on a distinguished road
Default

I have used this example in my application,

Using MKAnnotation, MKPinAnnotationView and creating a custom MKAnnotationView in an MKMapView The Reluctant Blogger

but its not calling calloutAccessoryControlTapped as well.

Code:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
	 NSLog(@"calloutAccessoryControlTapped");
}

can anyone help? it seems like a few people is having this problem.
svveet is offline   Reply With Quote
Old 07-28-2009, 07:56 PM   #18 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Australia
Posts: 180
svveet is on a distinguished road
Default

Quote:
Originally Posted by svveet View Post
I have used this example in my application,

Using MKAnnotation, MKPinAnnotationView and creating a custom MKAnnotationView in an MKMapView The Reluctant Blogger

but its not calling calloutAccessoryControlTapped as well.

Code:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
	 NSLog(@"calloutAccessoryControlTapped");
}

can anyone help? it seems like a few people is having this problem.
Problem solved!
My other view was blocking the mapview.
[self setUserInteractionEnabled:NO];
svveet is offline   Reply With Quote
Old 07-29-2009, 12:16 AM   #19 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 28
Posts: 156
Narender Mudgal is on a distinguished road
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Default How to make google earth type of application

Hi all,
I know here is a discussion of simple map in 3.0 and sorry to change the topic but my expectation is any one of you might be aware of it. I saw one application earthscape there they are using something like google earth. I would like to do something like that to move earth on my iphone screen. I dont have any idea how did they acheive that. Please direct me to the solution.
How to make google earth kind of application as native iphone application.
Narender Mudgal is offline   Reply With Quote
Old 02-21-2010, 10:15 AM   #20 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 1
Grych is on a distinguished road
Default

Hello,
You used that code to find if the annotation is this one showing the current location:
Code:
	if([[annotation title] isEqualToString:@"Current Location"])
It will work in English preferenceds. In the other languages this title is other (for example, "Bieżące położenie" in Polish). Better to use code like this:
Code:
       if ([annotation isMemberOfClass:[MyAnnotation class]] == NO)
--
Grych
iPhone development
Grych is offline   Reply With Quote
Old 03-23-2011, 02:09 PM   #21 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
macayer is on a distinguished road
Cool

For people wondering why their callout doesn't show up...
Make sure to set canShowCallOut = true for your Annotation View

Fixed the problem for me !
macayer is offline   Reply With Quote
Reply

Bookmarks

Tags
mkannotation, subtitle, title

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 312
8 members and 304 guests
blueorb, givensur, guusleijsten, jbro, mer10, n00b, SLIC, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:04 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0