ios - 在 iPhone 中使用 map View 读取当前位置名称
<p><p>我读取了当前位置的纬度和经度值,然后成功地将那个位置固定在 iPhone 中。现在我想用这个纬度和经度值来读取那个地名。</p>
<p>我使用下面的代码来读取查找当前位置:</p>
<pre><code>- (void)mapView:(MKMapView *)mapView1 didUpdateUserLocation:(MKUserLocation *)userLocation{
CLLocation *whereIAm = userLocation.location;
NSLog(@"I'm at %@", whereIAm.description);
latitude = whereIAm.coordinate.latitude;
longitude = whereIAm.coordinate.longitude;
NSLog(@"LAT : %f",latitude);
NSLog(@"LONG : %f",longitude);
mapView.mapType=MKMapTypeStandard;
;
;
;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude =latitude;//22.569722 ;
region.center.longitude = longitude;//88.369722;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
;
;
DisplayMap *ann = [ init];
ann.title = @" Welcome";
ann.subtitle = @"Hi";
ann.coordinate = region.center;
;
}
- (void)viewDidLoad {
;
mapView.showsUserLocation = YES;
mapView.delegate = self;
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: (id<MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *);
}
;
return pinView;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>像这样使用 MKReverseGeocoderDelegate 协议(protocol):</p>
<pre><code>@interface YourViewController : UIViewController <MKReverseGeocoderDelegate>
{
}
@implementation YourViewController
- (void)mapView:(MKMapView *)mapView1 didUpdateUserLocation:(MKUserLocation *)userLocation{
CLLocation *whereIAm = userLocation.location;
MKReverseGeocoder *reverseGeocoder = [ initWithCoordinate:whereIAm.coordinate];
reverseGeocoder.delegate = self;
;
}
</code></pre>
<p>现在实现以下方法委托(delegate)以获取响应:</p>
<pre><code>- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
NSLog(@"I'm at %@", placemark.locality);
}
</code></pre>
<p>有关更多信息,请查看:<a href="http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/" rel="noreferrer noopener nofollow">http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/</a> </p></p>
<p style="font-size: 20px;">关于ios - 在 iPhone 中使用 mapView 读取当前位置名称,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/3822297/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/3822297/
</a>
</p>
页:
[1]