ios - 如何获取所选 map 引脚的坐标数据?
<p><p>我正在尝试获取我在 map 上选择的每个大头针的坐标。我有一个问题,我选择的每个引脚都给我相同的值。 </p>
<p>在副标题中,我可以看到我选择的每个引脚的值,但是当我将它等于 Lat 和 Lon 字符串值时,它总是给我相同的值,因此 Lat 和 Lon 字符串值不会改变。那么请问我的问题在哪里?</p>
<pre><code>- (void)viewDidLoad{
CLLocationCoordinate2D annotationCoord;
annotationPoint.subtitle = ;
//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>我这样做是为了获取地址以获取前往 AppleMap 应用程序的方向。我需要我选择的引脚的值。</p>
<pre><code> - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != locationMap.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *);
if ( pinAnnotation == nil )
pinAnnotation = [[ 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 = ;
;
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
return pinAnnotation;
}
</code></pre>
<p>LAT 和 LON 的值始终相同。请问我的问题在哪里?</p>
<pre><code>-(void)infoButton:(id)sender{
NSString *str = ;
NSLog(@"Test %f, %f", Lat, Lon);
NSURL *URL = ;
[ openURL:URL];
}
</code></pre>
<p>测试解决方案:</p>
<pre><code>-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
MKPointAnnotation *annotationPoint = [ init];
CLLocation *pinLocation = [ initWithLatitude:annotationPoint.coordinate.latitude longitude:annotationPoint.coordinate.longitude];
NSLog(@"RESULT: Lat:%@ Long:%@", [coordinate].latitude,[coordinate].longitude);
}
</code></pre>
<p>NSLog 结果:<code>LAST:<+0.00000000,+0.00000000> +/- 0.00m(速度 -1.00 mps/course -1.00)@ 8/23/13,10:01:04 AM 标准时间</code></p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这行代码:</p>
<pre><code>CLLocation *pinLocation = [ initWithLatitude:[(MyAnnotation*) coordinate].latitude longitude:[(MyAnnotation*) coordinate].longitude];
</code></pre>
<p>在方法中:</p>
<pre><code>- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
</code></pre>
<p>希望对你有帮助!!</p></p>
<p style="font-size: 20px;">关于ios - 如何获取所选 map 引脚的坐标数据?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18380065/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18380065/
</a>
</p>
页:
[1]