[转Iphone]根据经纬度坐标取详细地址(包括国,省,市,街道,号)

 

获取当前手机地址,再从经纬度转换成详细地址(包括:国家名-国家代码,省,市,街道名,邮政代代码等)。

      1:获取当前手机经纬度

 

@implementation CurrentLocation

@synthesize locationManager;
@synthesize target,callBack;

#pragma mark --
#pragma mark Public
-(void) startUpdatingLocation{
	[[self locationManager] startUpdatingLocation];
}
#pragma mark --
#pragma mark Memory management
-(void) dealloc{
	[super dealloc];
	[locationManager release];
}
#pragma mark --
#pragma mark Location manager
/*
 Return a location manager -- create one if necessary.
 */
- (CLLocationManager *)locationManager {
    if (locationManager != nil) {return locationManager;}
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    [locationManager setDelegate:self];
    return locationManager;
}
#pragma mark --
#pragma mark CLLocationManagerDelegate methods
/*
 Conditionally enable the Add button:
 If the location manager is generating updates, then enable the button;
 If the location manager is failing, then disable the button.
 */
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation {
	NSLog(@"获取到经纬度!");
}
- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error {
        NSLog(@"获取失败!");
 }
@end

 

      2:  获取当前手机经纬度的详细地址

 

@implementation AddressReverseGeoder

#pragma mark --
#pragma mark Public
//根据经纬度开始获取详细地址信息
- (void)startedReverseGeoderWithLatitude:(double)latitude longitude:(double)longitude{
	CLLocationCoordinate2D coordinate2D;
	coordinate2D.longitude = longitude;
	coordinate2D.latitude = latitude;
	//
	MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate2D];
	geoCoder.delegate = self;
	[geoCoder start];
}
#pragma mark --
#pragma mark MKReverseGeocoderDelegate methods
//获得地址信息
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
	NSString *address = [NSString stringWithFormat:@"%@ %@ %@ %@ %@%@", 
									  placemark.country,
									  placemark.administrativeArea,
									  placemark.locality,
									  placemark.subLocality,
									  placemark.thoroughfare,
									  placemark.subThoroughfare];
	NSLog(@"经纬度所对应的详细:%@", address);
	geocoder = nil;
}
//错误处理
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
	NSLog(@"error %@" , error);
}
#pragma mark --
#pragma mark Memory management
- (void)dealloc {
    [super dealloc];
}
@end

@property (nonatomic, readonly) NSDictionary *addressDictionary; //地址字典

@property (nonatomic, readonly) NSString *thoroughfare; //街道名——“科韵路”

@property (nonatomic, readonly) NSString *subThoroughfare; // 门牌号——“18号”

@property (nonatomic, readonly) NSString *locality; //城市——“广州市”

@property (nonatomic, readonly) NSString *subLocality; //区县——“天河区”

@property (nonatomic, readonly) NSString *administrativeArea; //身份——“广东省”

@property (nonatomic, readonly) NSString *subAdministrativeArea; //没获取到,不知道是什么东东

@property (nonatomic, readonly) NSString *postalCode; //邮政编码——不知道是什么原因,这里没获取到

@property (nonatomic, readonly) NSString *country; //国家——“中国”

@property (nonatomic, readonly) NSString *countryCode; //国家代码——“CN”

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值