Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get coordinate data of selected map pin?
    text
    copied!<p>I am trying get the coordinate of each pin I select on my map. I have an issue that every pin I select it give me the same value. </p> <p>In the subtitle I can see the value of each pin I select but when I equal it to Lat and Lon string value it gives me always the same value so Lat and Lon string value won't change. So please where could be my issue?</p> <pre><code>- (void)viewDidLoad{ CLLocationCoordinate2D annotationCoord; annotationPoint.subtitle = [NSString stringWithFormat:@"%f &amp; %f", annotationPoint.coordinate.latitude, annotationPoint.coordinate.longitude]; //Lat and Lon are FLOAT. Lat = annotationPoint.coordinate.latitude; Lon = annotationPoint.coordinate.longitude; NSLog(@"Lat is: %f and Lon is: %f", Lat, Lon); } </code></pre> <p>I am doing this to get to the address to get direction to the AppleMap app. I need the values of the pin I selected.</p> <pre><code> - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { MKPinAnnotationView *pinAnnotation = nil; if(annotation != locationMap.userLocation) { static NSString *defaultPinID = @"myPin"; pinAnnotation = (MKPinAnnotationView *)[locationMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; if ( pinAnnotation == nil ) pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; pinAnnotation.canShowCallout = YES; //instatiate a detail-disclosure button and set it to appear on right side of annotation UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; [infoButton addTarget:self action:@selector(infoButton:) forControlEvents:UIControlEventTouchUpInside]; pinAnnotation.rightCalloutAccessoryView = infoButton; } return pinAnnotation; } </code></pre> <p>The value of the LAT and LON is always the same. Please where could be my problem?</p> <pre><code>-(void)infoButton:(id)sender{ NSString *str = [NSString stringWithFormat:@"http://maps.apple.com/maps?saddr=%f,%f&amp;daddr=%f,%f", Lat,Lon,lat1,lon1]; NSLog(@"Test %f, %f", Lat, Lon); NSURL *URL = [NSURL URLWithString:str]; [[UIApplication sharedApplication] openURL:URL]; } </code></pre> <p>Test for solution:</p> <pre><code>-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{ MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init]; CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:annotationPoint.coordinate.latitude longitude:annotationPoint.coordinate.longitude]; NSLog(@"RESULT: Lat:%@ Long:%@", [[view annotation]coordinate].latitude,[[view annotation]coordinate].longitude); } </code></pre> <p>NSLog result: <code>LAST: &lt;+0.00000000,+0.00000000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) @ 8/23/13, 10:01:04 AM Standard Time</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload