I have a MKMapView with a bunch of annotations but I can't add an action to them. I was just creating an MKPointAnnotation, but I couldn't add an action to that. Whenever I click the annotation, nothing happens. Here is how I am setting the annotations -
CLLocationCoordinate2D monteVista;
monteVista.latitude = (double) 37.83029;
monteVista.longitude = (double) -121.98827;
MKPointAnnotation *monteVistaPoint = [[MKPointAnnotation alloc] init];
monteVistaPoint.coordinate = monteVista;
monteVistaPoint.title = #"Monte Vista";
CLLocationCoordinate2D sanRamonValley;
sanRamonValley.latitude = (double) 37.82609;
sanRamonValley.longitude = (double) -122.00603;
MKPointAnnotation *sanRamonValleyPoint = [[MKPointAnnotation alloc] init];
sanRamonValleyPoint.coordinate = sanRamonValley;
sanRamonValleyPoint.title = #"San Ramon Valley";
CLLocationCoordinate2D doughertyValley;
doughertyValley.latitude = (double) 37.76845;
doughertyValley.longitude = (double) -121.90342;
MKPointAnnotation *doughertyValleyPoint = [[MKPointAnnotation alloc] init];
doughertyValleyPoint.coordinate = doughertyValley;
doughertyValleyPoint.title = #"Dougherty Valley";
NSArray *points = [[NSArray alloc] initWithObjects: monteVistaPoint, sanRamonValleyPoint, doughertyValleyPoint, nil];
[self.schoolMap addAnnotations:points];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
NSLog(#"Pin Created");
return annotationView;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
MKPointAnnotation *testPoint = [[MKPointAnnotation alloc] init];
testPoint = view.annotation;
self.testText.text = testPoint.title;
NSLog(#"Selected");
}
You need to change viewForAnnotation: method in order customize and then just implement openDetail: action method
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if (annotation == mapView.userLocation)
{
return nil;
}
static NSString *identifier = #"CustomAnnotation";
MKAnnotationView* annView = nil;
if ([annotation isKindOfClass:[CustomAnnotation class]]) {
annView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annView == nil) {
annView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annView.annotation = annotation;
}
UIImage *image = nil;
image = [UIImage imageNamed:#"pin2"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[annView addSubview:imageView];
[annView setFrame:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
// [annView setBackgroundColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.1]];
UIButton*accessory = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[accessory setTag:[(CustomAnnotation*)annotation tag]];
[accessory addTarget:self action:#selector(openDetail:) forControlEvents:UIControlEventTouchUpInside];
[accessory setFrame:CGRectMake(0, 0, 30, 30)];
[annView setRightCalloutAccessoryView:accessory];
}
[annView setEnabled:YES];
[annView setCanShowCallout:YES];
return annView;
}
Related
I have 2 MKPointAnnotation and i want to display them on map with two different pins(MKAnnotationView having image).
// MKPointAnnotation - 1
CLLocationCoordinate2D cordinate;
cordinate.latitude = [_latitudeString doubleValue];
cordinate.longitude = [_longitudeString doubleValue];
MKPointAnnotation *point1 = [[MKPointAnnotation alloc] init];
point1.coordinate = CLLocationCoordinate2DMake(cordinate.latitude, cordinate.longitude);
[self.mapView addAnnotation:point1];
P.S - When i get second MKPointAnnotation i needed self zoom on that area.
// MKPointAnnotation - 2
CLLocationCoordinate2D cordinate;
cordinate.latitude = [_latStr doubleValue];
cordinate.longitude = [_longStr doubleValue];
MKPointAnnotation *point2 = [[MKPointAnnotation alloc] init];
point2.coordinate = CLLocationCoordinate2DMake(cordinate.latitude, cordinate.longitude);
[self.mapView addAnnotation:point2];
//This is my code for MKAnnotationView
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if ([annotation isKindOfClass:[MKPointAnnotation class]]){
MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:#"CustomPinAnnotationView"];
if(!pinView){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"CustomPinAnnotationView"];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:#"annotation"];
pinView.calloutOffset = CGPointMake(0, 0);
}
else{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}
What i need to change in the viewForAnnotation method?
For example, you can create subclass of MKPointAnnotation.
#interface SecondAnnotation: MKPointAnnotation
#end
#implementation SecondAnnotation
#end
Add SecondAnnotation to the mapView.
// MKPointAnnotation - 2
...
SecondAnnotation *point2 = [[SecondAnnotation alloc] init];
point2.coordinate = CLLocationCoordinate2DMake(cordinate.latitude,
cordinate.longitude);
[self.mapView addAnnotation:point2];
You can use different MKAnnotationView with the following code.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if ([annotation isKindOfClass:[MKPointAnnotation class]]){
MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:#"CustomPinAnnotationView"];
if(!pinView){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"CustomPinAnnotationView"];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:#"Annotation"];
pinView.calloutOffset = CGPointMake(0, 0);
}
else{
pinView.annotation = annotation;
}
return pinView;
} else if ([annotation isKindOfClass:[SecondAnnotation class]]){
MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:#"CustomPinAnnotationView"];
if(!pinView){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"CustomPinAnnotationView"];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:#"Second"];
pinView.calloutOffset = CGPointMake(0, 0);
}
else{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}
Writing the viewForAnnotation as below solved my problem -
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if ([annotation isKindOfClass:[MKPointAnnotation class]]){
MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:#"CustomPinAnnotationView"];
if(!pinView){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"CustomPinAnnotationView"];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:#"annotation"];
pinView.calloutOffset = CGPointMake(0, 0);
}
else{
pinView.annotation = annotation;
if ([annotation isKindOfClass:[SecondAnnotation class]]) {
pinView.image = [UIImage imageNamed:#"range"];
}
else{
pinView.image = [UIImage imageNamed:#"annotation"];
}
}
return pinView;
}
return nil;
}
In my project I fill my map with these informations
for (int i = 0; i<arrayResults.count; i++){
object = [arrayResults objectAtIndex:i];
if ([[object iden]intValue] == 1) {
type = #"type_one";
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
[map addAnnotation:annotationPoint];
}
else if ([[object iden]intValue] == 2) {
type = #"type_two";
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
[map addAnnotation:annotationPoint];
}
else if ([[object iden]intValue] == 3) {
type = #"type_three";
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
[map addAnnotation:annotationPoint];
}
else if ([[object iden]intValue] == 4) {
type = #"type_four";
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
[map addAnnotation:annotationPoint];
}
these are four type of object that I add on my map
when I enter inside this method
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *view = nil;
if (annotation != mapView.userLocation) {
if ([[[arrayResults objectAtIndex:countPoint]iden]intValue] == 1){
view = [mapView dequeueReusableAnnotationViewWithIdentifier:#"type_one"];
if (!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"type_one"];
view.canShowCallout = YES;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[aButton addTarget:self action:#selector(open:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTag:countPoint+100];
view.rightCalloutAccessoryView = aButton;
view.image = [UIImage imageNamed:#"type_one.png"];
}
}
else if ([[[arrayResults objectAtIndex:countPoint]iden]intValue] == 2){
view = [mapView dequeueReusableAnnotationViewWithIdentifier:#"type_two"];
if (!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"type_two"];
view.canShowCallout = YES;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[aButton addTarget:self action:#selector(open:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTag:countPoint+100];
view.rightCalloutAccessoryView = aButton;
view.image = [UIImage imageNamed:#"type_two.png"];
}
}
else if ([[[arrayResults objectAtIndex:countPoint]iden]intValue] == 3){
view = [mapView dequeueReusableAnnotationViewWithIdentifier:#"type_three"];
if (!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"type_three"];
view.canShowCallout = YES;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[aButton addTarget:self action:#selector(open:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTag:countPoint+100];
view.rightCalloutAccessoryView = aButton;
view.image = [UIImage imageNamed:#"type_three.png"];
}
}
else if ([[[arrayResults objectAtIndex:countPoint]iden]intValue] == 4){
view = [mapView dequeueReusableAnnotationViewWithIdentifier:#"type_four"];
if (!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"type_four"];
view.canShowCallout = YES;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[aButton addTarget:self action:#selector(openScheda:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTag:countPoint+100];
view.rightCalloutAccessoryView = aButton;
view.image = [UIImage imageNamed:#"type_four.png"];
}
}
countPoint++;
}
The problem is that type of marker don't correspond with array element... but I don't understand.
That is if a marker has image "type_one", in the pop up it show "title" of type_four...it don't correspond
Your annotation needs to "know" what type it is so you can create the right kind of view in viewForAnnotation. Do so by subclassing MKPointAnnotation, adding an NSInteger value to it to store the array index.
See MKPointAnnotation add extra property, but you'll add an NSInteger property called index.
When creating your annotations, set this property:
for (int i = 0; i<arrayResults.count; i++)
{
object = [arrayResults objectAtIndex:i];
CLLocationCoordinate2D annotationCoord = CLLocationCoordinate2DMake([[[object coord]objectForKey:#"latitude"] floatValue], [[[object coord]objectForKey:#"longitude"] floatValue]);
// MKMyPointAnnotation is your MKPointAnnotation subclass
MKMyPointAnnotation *annotationPoint = [[MKMyPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = [NSString stringWithFormat:#"%#",[object nome_obj]];
annotationPoint.subtitle = [NSString stringWithFormat:#"%#",[object address]];
annotationPoint.index = i; // store the index
[map addAnnotation:annotationPoint];
}
Then in your viewForAnnotation, cast the annotation to your subclass, then dereference the type:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
{
MKMyPointAnnotation *myAnnotation = (MKMyPointAnnotation *)annotation;
object = [arrayResults objectAtIndex:myAnnotation.index]; // <-- your index property
switch ([[object iden] intValue])
{
case 1: // type one
.
.
.
}
.
.
.
}
How do I add a button to my placemarks and then get it to push onto a view controller?
- (void)viewDidLoad
{
[super viewDidLoad];
// Set "More" logo in navigation bar
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Navigation"]];
appDelegate=[[UIApplication sharedApplication] delegate];
// Set longatude and latitude to tyne and wear
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(54.995184, -1.566699);
// Set span to cover area
MKCoordinateSpan span = MKCoordinateSpanMake(0.5, 0.5);
// Set region
MKCoordinateRegion regionToDisplay = MKCoordinateRegionMake(center, span);
[self.nearbyMapView setRegion: regionToDisplay];
for (int i = 0; i < [[appDelegate offersFeeds] count]; i++)
{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
NSString *plotAddress = [[[appDelegate offersFeeds] objectAtIndex:i] valueForKey:#"addressline"];
NSString *plotTitle = [[[appDelegate offersFeeds] objectAtIndex:i] valueForKey:#"title"];
[geocoder geocodeAddressString:plotAddress completionHandler:^(NSArray *placemarks, NSError *error) {
if (placemarks && placemarks.count > 0)
{
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc]initWithPlacemark:topResult];
// Set title
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = placemark.location.coordinate;
pa.title = plotTitle;
// Add placemark to map
[self.nearbyMapView addAnnotation:pa];
}
}];
}
}
I've had a look at MKAnotationView but struggling to understand how to get this working with CLPlacemark.
Add this before you add mapview to self.view
-(void)viewDidLoad
{
MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
annotation.coordinate = yourCoordinate;
annotation.title = #"Title";
annotation.subtitle = #"SubTitle";
[mapView1 addAnnotation:annotation];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = #"identifier";
pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
{
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
annotationView.enabled = YES;
pinView.canShowCallout = YES;
UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//Accessoryview for the annotation view in ios.
pinView.rightCalloutAccessoryView = btn;
}
else
{
pinView.annotation = annotation;
}
pinView.annotation = annotation;
return pinView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
//Put your button stuff here...
}
I hope it is useful to you
In my map annotations, I have a UIButton as each accessory view in the callouts. In the - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control method, how do I figure out which accessory view was touched to handle each the events? Here's my code:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"current"];
UIButton *calloutButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIButton *directionsButton = [UIButton buttonWithType:UIButtonTypeCustom];
directionsButton.frame = CGRectMake(0, 0, 23, 23);
[directionsButton setBackgroundImage:[UIImage imageNamed:#"directions.png"] forState:UIControlStateNormal];
MyPin.leftCalloutAccessoryView = directionsButton;
MyPin.rightCalloutAccessoryView = calloutButton;
MyPin.draggable = NO;
MyPin.highlighted = NO;
MyPin.animatesDrop= YES;
MyPin.canShowCallout = YES;
MyPin.pinColor = MKPinAnnotationColorRed;
return MyPin;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
Annotation *ann = view.annotation;
if ([control tag] == 1) {
CLLocationCoordinate2D currentCoords = {ann.coordinate.latitude, ann.coordinate.longitude};
MKPlacemark *place = [[MKPlacemark alloc] initWithCoordinate: currentCoords addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark: place];
destination.name = ann.title;
destination.url = [NSURL URLWithString:#"http://www.wccca.com/PITS"];
NSArray *items = [[NSArray alloc] initWithObjects: destination, nil];
NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsDirectionsModeKey, nil];
[MKMapItem openMapsWithItems: items launchOptions: options];
}
if ([control tag] == 2) {
MKCoordinateRegion region;
region.center.latitude = ann.coordinate.latitude;
region.center.longitude = ann.coordinate.longitude;
region.span.latitudeDelta = 0.02;
region.span.longitudeDelta = 0.02;
[self.mapView setRegion:region animated:YES];
}
}
Rather than setting and using tags, you could just check if control is the left or right accessory view:
if (control == view.leftCalloutAccessoryView) {
//handle left control tap...
}
else
if (control == view.rightCalloutAccessoryView) {
//handle right control tap...
}
How do I show images instead of pins in the map. So far I can only add pins on tap. A sample code of the .m would extremely help since i'm still new to iOS programming.
#pragma mark -
#pragma mark MKMapView delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:#"someImage.png"];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:#selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
return nil;
}
EDIT:
I could explain to you all about the MKAnnotationView, but I think you will find the documentation provided by Apple to be a far better explanation than from any other source. Check the overview section in the link.
https://developer.apple.com/documentation/mapkit/mkannotationview
Go to organizer of Xcode and then go to documentation and search weatherMap it shows example for map with including images at annotation.
#pragma mark -
#pragma mark MKMapView delegate
-(void)addAllPinsOnMapView
{
MKCoordinateRegion region = mapViewOffer.region;
region.center = CLLocationCoordinate2DMake(12.9752297537231, 80.2313079833984);
region.span.longitudeDelta= 0.1f;
region.span.latitudeDelta= 0.1f;
[mapViewOffer setRegion:region animated:YES];
mapViewOffer.delegate=self;
arrMapPin=[[NSMutableArray alloc] init];
NSArray *name=[[NSArray alloc]initWithObjects:
#"Title1",
#"Title2",
#"Title3", nil];
NSMutableArray *arrCoordinateStr = [[NSMutableArray alloc] initWithCapacity:name.count];
[arrCoordinateStr addObject:#"12.970760345459,80.2190093994141"];
[arrCoordinateStr addObject:#"12.9752297537231,80.2313079833984"];
[arrCoordinateStr addObject:#"12.9788103103638,80.2412414550781"];
for(int i = 0; i < name.count; i++)
{
NSArray *components = [[arrCoordinateStr objectAtIndex:i] componentsSeparatedByString:#","];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
mapPin.title = [name objectAtIndex:i];
mapPin.coordinate = coordinate;
[mapViewOffer addAnnotation:mapPin];
}
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:
(MKAnnotationView *)view
{
NSLog(#"%#",view.annotation.title);
NSLog(#"%f",view.annotation.coordinate.latitude);
NSLog(#"%f",view.annotation.coordinate.longitude);
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(calloutTapped:)];
[view addGestureRecognizer:tapGesture];
}
-(void)calloutTapped:(UITapGestureRecognizer *) sender
{
NSLog(#"Callout was tapped");
MKAnnotationView *view = (MKAnnotationView*)sender.view;
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
//[self performSegueWithIdentifier:#"annotationDetailSegue" sender:annotation];
OfferDetailsViewController *objOfferDetailsViewController = [[OfferDetailsViewController alloc]init];
[self.navigationController pushViewController:objOfferDetailsViewController animated:YES];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)theMapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = #"annotationViewID";
pinView = (MKAnnotationView *)[mapViewOffer dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
}
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:#"placeholder"];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:#selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
return pinView;
}