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


以当前手机为例:

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

      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

 

转载于:https://www.cnblogs.com/Win-Iphone_QG/archive/2010/12/16/1908541.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值