ios 高德地图 通过索引输出经纬度 根据经纬度 定位

ios 高德地图 通过索引输出经纬度 根据经纬度 定位,有需要的朋友可以参考下。


ios 高德地图新出了几个方法,实现地理位置的编码用到了CLGeocoder,CLGeocoder里面一共就下面这几种方法:

//根据location即经纬度输出具体地址

- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler;

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{

CLLocation * location = [locations firstObject];
self.repairsMapView.latitude = location.coordinate.latitude;
self.repairsMapView.longitude = location.coordinate.longitude;

CLGeocoder * geocoder = [[CLGeocoder alloc]init];

[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {

//这时的placemarks数组里面只有一个元素


CLPlacemark * placemark = [placemarks firstObject];
NSLog(@"%@",placemark.addressDictionary); //根据经纬度会输出该经纬度下的详细地址 国家 地区 街道 之类的



}
}];

[manager stopUpdatingLocation];

}

//根据具体地址输出经纬度

- (void)geocodeAddressDictionary:(NSDictionary *)addressDictionary completionHandler:(CLGeocodeCompletionHandler)completionHandler;
- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;
- (void)geocodeAddressString:(NSString *)addressString inRegion:(CLRegion *)region completionHandler:(CLGeocodeCompletionHandler)completionHandler;

我就以- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;来做下说明

在使用CLGeocoder之前 需要 导入#import 即corelocation.framework

CLGeocoder * geocoder = [[CLGeocoder alloc]init];

[geocoder geocodeAddressString:@"北京市长城" completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"%@",placemarks);

}];

//输出结果如下:

(
"Beijing Fengtai Great Wall (New Century Clothing Mansion), Beijing Fengtai Great Wall (New Century Clothing Mansion), Fengtai, Beijing China @ <+39.85067600,+116.39916000> +/- 100.00m, region CLCircularRegion (identifier:'<+39.85067650,+116.39916000> radius 57.99', center:<+39.85067650,+116.39916000>, radius:57.99m)"
)

你可能感兴趣的:(ios开发)