我有一个 MKMapView
并想根据 MKMapView
的中心获取城市名称。我根本不想删除任何图钉或注释。只需根据 MKMapView
位置的中心自动抓取数据。我知道有这种方法“[placemarkName locality]”。但是有没有不使用地标的方法呢?
最佳答案
您可以从 map View 的 centerCoordinate
执行 reverseGeocodeLocation
(有效 iOS 5+)。例如,我可以这样做:
CLLocationCoordinate2D center = self.mapView.centerCoordinate;
CLGeocoder *coder = [[CLGeocoder alloc] init];
[coder reverseGeocodeLocation:[[CLLocation alloc] initWithLatitude:center.latitude longitude:center.longitude] completionHandler:^(NSArray *placemarks, NSError *error) {
self.cityLabel.text = [[placemarks firstObject] locality];
}];
诚然,这会返回一组地标,但在提取城市名称后您无需对它们执行任何操作。
关于ios - 是否可以根据 map View 的中心抓取城市等信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21247952/