高德地图看各省分界线_高德地图定位城市区域

h文件

引入CoreLocation/CoreLocation.h

@interface

WeatherViewController :UIViewController<CLLocationManagerDelegate>{

CLLocationManager*

locationManager;

}

@property

(strong,

nonatomic)

CLLocationManager*

locationManager;

@end

.m文件

//开始定位

-(void)startLocation{

self.locationManager =

[[CLLocationManager alloc] init];

self.locationManager.delegate

= self;

self.locationManager.desiredAccuracy

= kCLLocationAccuracyBest;

self.locationManager.distanceFilter

= 10.0f;

[self.locationManager

startUpdatingLocation];

}

//定位代理经纬度回调

-(void)locationManager:(CLLocationManager

*)manager didUpdateToLocation:(CLLocation

*)newLocation fromLocation:(CLLocation

*)oldLocation {

[locationManager

stopUpdatingLocation];

NSLog(@"location

ok");

NSLog(@"%@",[NSString stringWithFormat:@"经度:%3.5f\n纬度:%3.5f",newLocation.coordinate.latitude,newLocation.coordinate.longitude]);

CLGeocoder * geoCoder =

[[CLGeocoder alloc] init];

[geoCoder reverseGeocodeLocation:newLocation

completionHandler:^(NSArray

*placemarks, NSError *error) {

for (CLPlacemark * placemark

in

placemarks) {

NSDictionary *test =

[placemark addressDictionary];

// Country(国家) State(城市) SubLocality(区)

NSLog(@"%@", [test

objectForKey:@"State"]);

}

}];

}

#pragma

mark 根据地名确定地理坐标

-(void)getCoordinateByAddress:(NSString

*)address{

//地理编码

[_geocoder geocodeAddressString:address

completionHandler:^(NSArray *placemarks, NSError *error) {

//取得第一个地标,地标中存储了详细的地址信息,注意:一个地名可能搜索出多个地址

CLPlacemark *placemark=[placemarks firstObject];

CLLocation

*location=placemark.location;//位置

CLRegion *region=placemark.region;//区域

NSDictionary *addressDic= placemark.addressDictionary;//详细地址信息字典,包含以下部分信息

// NSString *name=placemark.name;//地名

// NSString

*thoroughfare=placemark.thoroughfare;//街道

// NSString

*subThoroughfare=placemark.subThoroughfare; //街道相关信息,例如门牌等

// NSString *locality=placemark.locality; //

城市

// NSString *subLocality=placemark.subLocality; //

城市相关信息,例如标志性建筑

// NSString

*administrativeArea=placemark.administrativeArea; // 州

// NSString

*subAdministrativeArea=placemark.subAdministrativeArea;

//其他行政区域信息

// NSString *postalCode=placemark.postalCode;

//邮编

// NSString

*ISOcountryCode=placemark.ISOcountryCode; //国家编码

// NSString *country=placemark.country;

//国家

// NSString *inlandWater=placemark.inlandWater;

//水源、湖泊

// NSString *ocean=placemark.ocean; // 海洋

// NSArray

*areasOfInterest=placemark.areasOfInterest; //关联的或利益相关的地标

NSLog(@"位置:%@,区域:%@,详细信息:%@",location,region,addressDic);

}];

}

#pragma

mark 根据坐标取得地名

-(void)getAddressByLatitude:(CLLocationDegrees)latitude

longitude:(CLLocationDegrees)longitude{

//反地理编码

CLLocation *location=[[CLLocation

alloc]initWithLatitude:latitude longitude:longitude];

[_geocoder

reverseGeocodeLocation:location completionHandler:^(NSArray

*placemarks, NSError *error) {

CLPlacemark *placemark=[placemarks

firstObject];

NSLog(@"详细信息:%@",placemark.addressDictionary);

}];

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值