MKAnnotations not showing up until I scroll the map - iphone

Well, I have a view with a map where I load some annotations. Everything works fine, but when I want to erase those annotations and include other annotations they do not show up until I move (scroll) the map.
Any suggestion?
EDITED:
Seems like instead of using this:
[self updateMap];
I have to use:
[self performSelectorOnMainThread:#selector(updateMap) withObject:nil waitUntilDone:true];
Being update map the method where I add my new annotations.

Try smth like this:
[mapView removeAnnotations:[mapView annotations]];
NSArray *targetArray = /*YOUR ARRAY NAME with object, containing `latitude`, `longitude` and `title` values*/
for (id *item in targetArray) {
if (item.latitude && item.longitude) {
MKPin *pin = [[MKPin alloc] init]; // MKPin is your class which specifies the deledate `MKAnnotation`
pin.coordinate = CLLocationCoordinate2DMake(item.latitude, item.longitude);
pin.title = item.title;
[mapView addAnnotation:pin];
}
}

In the viewdidload use :
- (void)viewDidLoad
{
NSMutableArray* annotations=[[NSMutableArray alloc] init];
MyAnnotation* myAnnotation = [[MyAnnotation alloc] init];
myAnnotation.coordinate = theCoordinate;
[annotations addObject:myAnnotation];
MKMapRect flyTo = MKMapRectNull;
for (id <MKAnnotation> annotation in annotations)
{
NSLog(#"fly to on");
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(flyTo))
{
flyTo = pointRect;
}
else
{
flyTo = MKMapRectUnion(flyTo, pointRect);
//NSLog(#"else-%#",annotationPoint.x);
}
}
// Position the map so that all overlays and annotations are visible on screen.
mapView.visibleMapRect = flyTo;
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(#"welcome into the map view annotation");
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.draggable = NO;
pinView.pinColor=MKPinAnnotationColorGreen;
//button on the right for popup for pins
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
//zoom button on the left of popup for pins
UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[leftButton setTitle:annotation.title forState:UIControlStateNormal];
[leftButton addTarget:self
action:#selector(zoomToLocation:) forControlEvents:UIControlEventTouchUpInside];
pinView.leftCalloutAccessoryView = leftButton;
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"profile.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];
return pinView;
}
Hopefully this helps !!!!!!!!!

Related

MapView MKAnnotation not showing callout on MKMapView

I'm displaying a few map pins on a map view. I can't figure out why the callout won't show when an annotation is touched. Here's my code. I have some conditional code in the viewDidLoad method to display a different pin image depending on a category id. The custom pins display correctly, but when you touch them nothing happens.
thanks for any help with this.
- (void)viewDidLoad {
[super viewDidLoad];
[self requestData];
CLLocationCoordinate2D centerCoord = CLLocationCoordinate2DMake(44.2632, 11.4403);
MKCoordinateSpan span;
span.latitudeDelta=5;
span.longitudeDelta=5;
MKCoordinateRegion ITRegion = MKCoordinateRegionMake(centerCoord, span);
ITRegion.span=span;
[mapView setRegion: ITRegion animated: YES];
mapView.delegate=self;
[self.mapView setShowsUserLocation:YES];
for (int i=0; i<[publicDataArray count]; i++) {
MKPointAnnotation* annotation= [MKPointAnnotation new];
CLLocationCoordinate2D coordinate;
coordinate.latitude = [[[[publicDataArray objectAtIndex:i] objectForKey:#"address"] objectForKey:#"lat"] doubleValue];
coordinate.longitude = [[[[publicDataArray objectAtIndex:i] objectForKey:#"address"] objectForKey:#"lng"] doubleValue];
NSString *catId = [NSString stringWithFormat:#"%#",[[publicDataArray objectAtIndex:i] objectForKey:#"category_id"]];
if ([catId isEqual: #"213"]) {
annView.image = [UIImage imageNamed:#"comprareMap.png"];//sets image for pin
} else if ([catId isEqual:#"217"]) {
annView.image = [UIImage imageNamed:#"vedereMap.png"];//sets image for pin
} else if ([catId isEqual:#"221"]) {
annView.image = [UIImage imageNamed:#"mangiareMap.png"];//sets image for pin
}
annotation.coordinate = coordinate;
[mapView addAnnotation: annotation];
}
}
- (MKAnnotationView *) mapView:(MKMapView *)mapingView viewForAnnotation:(id <MKAnnotation>) annotation {
annView = nil;
if(annotation != mapingView.userLocation)
{
static NSString *defaultPinID = #"";
annView = (MKAnnotationView *)[mapingView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( annView == nil )
annView = [[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] ;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = rightButton;
annView.canShowCallout = YES;
}
return annView;
}

Detail Disclosure Indicator MKMap to Custom View Controller

EXTRA CODE ADDED
I am new to xcode. I have managed to create annotations on my map in various different colours. What I would like to do is have each annotation lead to somewhere new with a disclosure button. I have implemented a right arrow disclosure button now what I need to know is how I link that up so that each annotation will lead to a different view controller of my choice. Here is my current code on my MapViewController implementation.
MainMapViewController.m
#import "MainMapViewController.h"
#import "LocationAnnotation.h"
#interface MainMapViewController ()
#end
//Totnes Main Centre Coordinates
#define Totnes_LATITUDE 50.433741
#define Totnes_LONGITUDE -3.685797
//The Dartmouth Inn Coordinates
#define DARTMOUTH_INN_LATITUDE 50.430036;
#define DARTMOUTH_INN_LONGITUDE -3.683873;
//Pub Offers Co-Ordinates
#define TheKingBill_LATITUDE 50.431379
#define TheKingBill_LONGITUDE -3.685495
#define TheSevenStars_LATITUDE 50.431045
#define TheSevenStars_LONGITUDE -3.682945
#define TheLordNelson_LATITUDE 50.430931
#define TheLordNelson_LONGITUDE -3.683644
//Span
#define THE_SPAN 0.01f;
#implementation MainMapViewController
#synthesize mainMapView;
- (void)viewDidLoad
{
[super viewDidLoad];
//Set Delegate
mainMapView.delegate = self;
//Create the region
MKCoordinateRegion myRegion;
//Centre
CLLocationCoordinate2D centre;
centre.latitude = Totnes_LATITUDE;
centre.longitude = Totnes_LONGITUDE;
//Span
MKCoordinateSpan span;
span.latitudeDelta = THE_SPAN;
span.longitudeDelta = THE_SPAN;
myRegion.center = centre;
myRegion.span = span;
//Set The Map View
[mainMapView setRegion:myRegion animated:YES];
//Annotation
NSMutableArray * locations = [[NSMutableArray alloc] init];
LocationAnnotation * myAnn;
//The King Bill Annotation
myAnn = [[LocationAnnotation alloc] initWithTitle:#"The King Bill"
andSubtitle:#"Another Pub In Town"
andCoordinate:CLLocationCoordinate2DMake(TheKingBill_LATITUDE, TheKingBill_LONGITUDE)
andID:1];
[locations addObject:myAnn];
//The Seven Stars Annotations
myAnn = [[LocationAnnotation alloc] initWithTitle:#"The Royal Seven Stars Hotel"
andSubtitle:#"Hotel In Town"
andCoordinate:CLLocationCoordinate2DMake(TheSevenStars_LATITUDE, TheSevenStars_LONGITUDE)
andID:2];
[locations addObject:myAnn];
//The Lord Nelson Annotations
myAnn = [[LocationAnnotation alloc] initWithTitle:#"The Lord Nelson"
andSubtitle:#"Great Pub In Centre of Town"
andCoordinate:CLLocationCoordinate2DMake(TheLordNelson_LATITUDE, TheLordNelson_LONGITUDE)
andID:3];
[locations addObject:myAnn];
[self.mainMapView addAnnotations:locations];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - MKMapViewDelegate
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"pin"];
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView = rightButton;
int annId = ((LocationAnnotation *)annotation).idNumber;
annView.pinColor = (annId == 1) ? MKPinAnnotationColorPurple
: (annId == 2) ? MKPinAnnotationColorGreen
: MKPinAnnotationColorRed;
annView.canShowCallout = YES;
return annView;
}
#end
set rightbutton's tag to annID.
rightButton.tag = annId;
and then assign Selector to touchup event:
[rightButton addTarget:self action:#selector(YourMethod:) forControlEvents:UIControlEventTouchUpInside];
In YourMethod, you can use senders tag for navigating to different view
-(void)YourMethod:(UIButton*)sender
{
if(sender.tag==1)
{
//push viewcontroller1
}
else
{
//push viewcontroller
}
return;
}
As you can see, your right button is of type UIButton. Because of this fact you can addTarget to it:
[rightButton addTarget:self action:#selector(YourMethod) forControlEvents:UIControlEventTouchUpInside];
After user tap on rightButton YourMethod will be launched.
So for every pin you can add different button with different method, in the same way you are setting AnnotationColor
int annId = ((LocationAnnotation *)annotation).idNumber;
if (annId == 1)
{
annView.pinColor = MKPinAnnotationColorPurple;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView = rightButton;
[rightButton addTarget:self action:#selector(MethodWhereYouWillFireYouNewViewController) forControlEvents:UIControlEventTouchUpInside];
}
else if (annId == 2)
{
//similar as above
}
Check This:
-(void)clickOnMapAnnotation:(UIButton*)sender
{
int AnnotationClicked =sender.tag;
if(AnnotationClicked ==1)
{
//PushViewcontroller1
}
else
{
//PushViewcontroller1
}
}
(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id ) annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"pin"];
int annId = ((LocationAnnotation *)annotation).idNumber;
annView.pinColor = (annId == 1) ? MKPinAnnotationColorPurple
: (annId == 2) ? MKPinAnnotationColorGreen
: MKPinAnnotationColorRed;
//The Detail Disclosure button that I want to lead to a new view controller.
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:#selector(clickOnMapAnnotation:) forControlEvents:UIControlEventTouchUpInside];
rightButton.tag = annId;
annView.rightCalloutAccessoryView = rightButton;
annView.canShowCallout = YES;
return annView;
}

adding button to annotation bubble in mapview

The following is my code for adding annotation into a mapview. This code is called in viewdidload method
-(void)displayMYMap
{
MKCoordinateRegion region = mapView.region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
addAnnotation = [[[AddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:passedRecordID]autorelease];
[mapView addAnnotation:addAnnotation];
region.span=span;
region.center=mapCenter;
}
I am trying to add a button to my annotation bubble. I am getting an exception while I am trying to add the button to the annotationview.
UIButton *informationButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure ];
addAnnotation.rightCalloutAccessoryView = informationButton;
This is the code I have written to add the button. I cant figure out a reason for the exception.
use delegate method of Annotation,
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
static NSString *identifier = #"RoutePinAnnotation";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
if ([(UICCircleAnnotation *)annotation annotationType] == UICCircleAnnotationTypeOther) {
pinView.pinColor = MKPinAnnotationColorPurple;
} else if ([(UICCircleAnnotation *)annotation annotationType] == UICCircleAnnotationTypeContact) {
pinView.pinColor = MKPinAnnotationColorRed;
}
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:#selector(buttonMethod:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"profile.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];
return pinView;
}
in delegate method of Annotation View,
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
static NSString *identifier = #"RoutePinAnnotation";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
if ([(UICCircleAnnotation *)annotation annotationType] == UICCircleAnnotationTypeOther) {
pinView.pinColor = MKPinAnnotationColorPurple;
} else if ([(UICCircleAnnotation *)annotation annotationType] == UICCircleAnnotationTypeContact) {
pinView.pinColor = MKPinAnnotationColorRed;
}
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return pinView;
}
You will get disclosure button on the annotation bubble.

show users location blue point in iPhone MKMapView

I am developing a custom pins in a MapView in my iPhone app.
Here is the code:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = #"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
if ([[annotation title] isEqualToString:NSLocalizedString(#"Current Location",#"")]) {
MKPinAnnotationView *pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
//pin.pinColor = MKPinAnnotationColorRed;
annotationView = pin;
}
else
{
NSString *pin = [NSString stringWithFormat:#"pin%i.png",[[annotation imgNumber] intValue]];
annotationView.image = [UIImage imageNamed:pin];//Canviar la chincheta per numero
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[annotationView setRightCalloutAccessoryView:button];
annotationView.annotation = annotation;
annotationView.canShowCallout = YES;
/********* Imagen a la izquierda en la burbuja *********/
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// 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:#"botocorreu.png"] forState:UIControlStateNormal];
NSString *detailButton = [NSString stringWithFormat:#"%i",[[annotation imgNumber] intValue]];
[myDetailButton setImage:[UIImage imageNamed:detailButton] forState:UIControlStateNormal];
// Set the button as the callout view
annotationView.leftCalloutAccessoryView = myDetailButton;
annotationView.canShowCallout = YES;
}
return annotationView;
}
This works good but show me the users location with a red pin.
I check the "show user location" in the IB.
i would like to use the default blue point which will move it automatically when the user is moving, isn't correct?
How can i do that?
Thanks a lot.
Add this to the top of the viewForAnnotation method:
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
The special user location annotation is of type MKUserLocation and returning nil in that case tells the map view to draw the default view for it which is the blue dot.
You can also remove these lines since they will no longer be needed:
if ([[annotation title] isEqualToString:NSLocalizedString(#"Current Location",#"")]) {
MKPinAnnotationView *pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
//pin.pinColor = MKPinAnnotationColorRed;
annotationView = pin;
}
else

Why does a custom MKMapView annotation image disappear on touch?

I am annotating my map and setting an image just fine, but when I tap the annotation on the MapView, the image goes from my custom image back to the red pin. Why is this?
- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
MKPinAnnotationView *annotation = [[MKPinAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:#"currentloc"];
if (annotation == nil) {
annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:#"currentloc"];
}
annotation.image = [UIImage imageNamed:#"anno.png"];
annotation.canShowCallout = YES;
annotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bus_stop_30x30.png"]];
annotation.leftCalloutAccessoryView = imgView;
return annotation;
}
My code looks identical to some sample code that does not produce this problem.
Answering my own question here, just in case others have the same issue. Notice that I am using "MKPinAnnotationView" - it should be changed to "MKAnnotationView" and everything works.
Fixed code:
- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
MKAnnotationView *annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:#"currentloc"];
if (annotation == nil) {
annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:#"currentloc"];
}
annotation.image = [UIImage imageNamed:#"anno.png"];
annotation.canShowCallout = YES;
annotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bus_stop_30x30.png"]];
annotation.leftCalloutAccessoryView = imgView;
return annotation;
}
I think this is one of the best ways:
(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
NSLog(#"welcome into the map view annotation");
MyAnnotation* myAnnotation1=annotation;
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if([mapView isEqual:mapMainView]== NO)
{
return nil;
}
// try to dequeue an existing pin view first
// if ([annotation isKindOfClass:[myAnnotation1 class]])
// {
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (nil == pinView)
{
MKAnnotationView* annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier] autorelease];
// annotationView.canShowCallout = YES;
// pinView.animatesDrop=YES;
//pinView.pinColor=MKPinAnnotationColorPurple;
//image
UIImage* flagImage = [UIImage imageNamed:#"map_marker_over2.png"];
CGRect resizeRect;
resizeRect.size = flagImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[MapPropertyViewController annotationPadding],
[MapPropertyViewController annotationPadding]).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [MapPropertyViewController calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[flagImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
rightButton.tag = myAnnotation1.tagAnnotation;
annotationView.rightCalloutAccessoryView = rightButton;
profileIconView = [[UIImageView alloc]initWithFrame:CGRectMake(18.5f, 10.0f, 37.0f, 30.0f)];
annotationView.leftCalloutAccessoryView = profileIconView;
//image
img = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:[arrImages objectAtIndex:myAnnotation1.tagAnnotation]]]];
NSLog(#"Annotation Click %d",[arrImages count]);
NSLog(#"image %#",img);
profileIconView.image=img;
[profileIconView release];
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}
return pinView;
// }
// return nil;
}
Try this if you want to set both Source to Destination pin images different.
MKPointAnnotation * sourceAnno= [[MKPointAnnotation alloc] init];
sourceAnno.coordinate=CLLocationCoordinate2DMake(YourSourcelatitude,YourSourcelongitude);
[sourceAnno setAccessibilityLabel:#“Source”];
sourceAnno.title = #“You”;
[mapview addAnnotation: sourceAnno];
DestinationAnno = [[MKPointAnnotation alloc] init];
DestinationAnno.coordinate = CLLocationCoordinate2DMake(YourDestinationlatitude,YourDestinationlongitude);
[DestinationAnno setAccessibilityLabel:#“Destination”];
DestinationAnno.title =#“Destination”;
[mapview addAnnotation: DestinationAnno];
In Delegate Method
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPointAnnotation *PointAnno=(MKPointAnnotation *)annotation;
NSString * kPinAnnotationIdentifier = PointAnno.accessibilityLabel;
MKAnnotationView *AnnotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:kPinAnnotationIdentifier];
if ([kPinAnnotationIdentifier isEqualToString:#"Source"])
{
AnnotationView.centerOffset = CGPointMake(8, -14);
AnnotationView.calloutOffset = CGPointMake(-8, 0);
AnnotationView.image = [UIImage imageNamed:#"pin_blue.png"];
AnnotationView.canShowCallout = YES;
}
else if([kPinAnnotationIdentifier isEqualToString:#"Destination"])
{
AnnotationView.centerOffset = CGPointMake(8, -14);
AnnotationView.calloutOffset = CGPointMake(-8, 0);
AnnotationView.image = [UIImage imageNamed:#"pin_red.png"];
AnnotationView.canShowCallout = YES;
}
return AnnotationView;
}
Thank you