alt text http://www.freeimagehosting.net/uploads/a96118564f.png
In above image, You can see the numbers on the pin.
I don't want that numbers, Instead, when user clicks on that pin, Address of that location should be displayed?
I don't know how? I have heard about customizing the pin. I am trying. But if you know, would you help me plz.
Thanks in advance.
You've got two options here:
If all you want to do is take a latitude/longitude and present it as an address on the map, you'll need to use the MKReverseGeocoder
class which will spit out a MKPlacemark
that can then be added to your MKMapView
using addAnnotation:
.
If you've got some class of "thing" you'd like added to the map such as a "Person", you should make the class conform to the MKAnnotation
protocol (ie it needs a coordinate, title and subtitle property). You can then implement the mapView:viewForAnnotation:
method on your MKMapView
delegate and return a custom subclass of MKAnnotationView
. This will get added to the map when your "Person" becomes visible in the map view.
If you are using MKMapView
, then you need to create your own MKAnnotation
to add to the map. The annotation class implement the following instance methods:
- (NSString *)title
- to return the title of the pin, which is usually the first line
- (NSString *)subtitle
- to return the subtitle of the pin, which is usually the second line.
Thanks a lot, you made my day, i was very surprised what it is happening when i found that my subtitle is not taking nsstring stringwithformat, it was crashing and it was taking it when i assigned direct same hardcoded value in string format. very strange , now atleast it is not crashing thanks a lot for the solution
Yep, I got Something Different Solution. As per the instructions of @msaeed, I have changed the constructor of my class. i have implemented following code & it works as what i required
-(NSString *)subtitle {
return [NSString stringWithFormat:@"%f",coordinate.latitude];
}
-(NSString *)title {
return Title;
// return [NSString stringWithFormat:@"%f",coordinate.longitude];
}
-(id)initWithCoordinate: (CLLocationCoordinate2D) c
{
coordinate=c;
return self;
}
-(id)initWithCoordinate: (CLLocationCoordinate2D) c Title:(NSString*)xz
{
coordinate=c;
if(self=[super init])
{
if(Title!=nil)
[Title release];
Title=[[NSString alloc]initWithString:xz];
}
return self;
}
watch out the following image, that i have solved. image solved. http://www.freeimagehosting.net/uploads/fae045c2bf.png
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.