地址转经纬度(IOS自带方法)
来源:互联网 发布:细说php第二版视频教程 编辑:程序博客网 时间:2024/05/29 18:37
地址转经纬度(IOS自带方法)
1、导入头文件
#import <CoreLocation/CoreLocation.h>
2、定义全局变量
//定义CLGeocoder反向地理编码
CLGeocoder *_geocoder;
//传给接口的经纬度
NSString *_latitude;//纬度
NSString *_longitude;//经度
3、在viewDidLoad中初始化_geocoder,并调用地址转经纬度方法
- (void)viewDidLoad {
[super viewDidLoad];
_geocoder=[[CLGeocoder alloc]init];
[self getCoordinateByAddress:@"上海市徐汇区漕溪北路41号"];
}
4、地址转经纬度方法(_longitude,_latitude就是地址解析后的经纬度)
#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);
CLLocationDegrees latitude=location.coordinate.latitude;
CLLocationDegrees longitude=location.coordinate.longitude;
NSLog(@"纬度-->%lf,经度-->%lf",latitude,longitude);
//传给接口的纬度和经度
_latitude=[NSString stringWithFormat:@"%lf",latitude];
_longitude=[NSString stringWithFormat:@"%lf",longitude];
}];
}
- 地址转经纬度(IOS自带方法)
- ios系统经纬度转百度经纬度及经纬度转地址
- iOS 自带定位CLLocationManager获取经纬度以及城市名称
- 输入地址获得经纬度(一个方法)
- iOS 自带方法解析json
- IOS自带处理缓存方法
- ios 定位经纬度 地址解析
- ios输入地址得出经纬度
- java通过地址获得经纬度(转)
- 地址转经纬度(百度)function
- google经纬度转地址
- iOS小问题---iOS SDK自带md5加密方法
- 经纬度地址转换的方法集合(Python描述)
- IOS中四种解析JSON的方法(IOS5自带支持方法、JSONKit、SBJson、TouchJson)
- iOS 自带定位最新获取 街区名字 、街道名字、城市名字、省份等,并获取当经纬度。
- iOS_二维码扫描(iOS自带)
- iOS_二维码扫描(iOS自带)
- iOS 二维码(系统自带)
- 数据库断电后DB状态为可疑解决方法(事例数据库为DataValidatation)
- 数据库断电后DB状态为可疑解决方法(事例数据库为DataValidatation)
- Mysql随机插入数字、日期、时间戳
- python数据库连接模板
- Java integer to byte array
- 地址转经纬度(IOS自带方法)
- 滚动固定导航
- 子查询
- JNI编程-- undefined reference to `__android_log_print' 的解决办法
- iOS 图片边缘抗锯齿
- 记录点滴
- 探究functools模块wraps装饰器的用途
- 【java基础】java通过相对路径读取文件
- layoutSubViews实践