ios如何根据经纬度坐标取详细地址
2015-01-22来源:易贤网

以当前手机为例:

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

1:获取当前手机经纬度

Reverse geoder Class

1:- (void)startedReverseGeoderWithLatitude:(double)latitude longitude:(double)longitude{ CLLocationCoordinate2D coordinate2D; coordinate2D.longitude = longitude; coordinate2D.latitude = latitude; // if (self.locationInfo == nil) { self.locationInfo = [[[Location alloc] init] autorelease]; } self.locationInfo.latitude = latitude; self.locationInfo.longitude = longitude; // MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate2D]; geoCoder.delegate = self; [geoCoder start];}#pragma mark -#pragma mark MKReverseGeocoderDelegate methods- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { NSLog(@"reverse finished..."); NSLog(@"country:%@",placemark.country); NSLog(@"countryCode:%@",placemark.countryCode); NSLog(@"locality:%@",placemark.locality); NSLog(@"subLocality:%@",placemark.subLocality); NSLog(@"postalCode:%@",placemark.postalCode); NSLog(@"subThoroughfare:%@",placemark.subThoroughfare); NSLog(@"thoroughfare:%@",placemark.thoroughfare); NSLog(@"administrativeArea:%@",placemark.administrativeArea); self.locationInfo.locationName = [NSString stringWithFormat:@"%@ @ @", placemark.country, placemark.administrativeArea, placemark.locality, placemark.subLocality, placemark.thoroughfare]; NSLog(@"administrativeArea:%@",self.locationInfo.locationName); [self.target performSelector:self.callBack withObject:@"0"]; geocoder = nil;}- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { NSLog(@"error %@" , error); [self.target performSelector:self.callBack withObject:@"1"];}

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

Current location class

-(void) startUpdatingLocation{ // Start the location manager. [[selflocationManager] startUpdatingLocation]; }#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;}/** 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 { [self.target performSelector:self.callBack withObject:@"0"];}- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { [self.target performSelector:self.callBack withObject:@"1"];}

更多信息请查看IT技术专栏

推荐信息