¿Cómo get el nombre de la location del dispositivo en el iPhone?

Actualmente estoy trabajando en la aplicación de iPhone, usando CLLocationManager para get valores de Latitud y Longitud bien. ¿No sabía esto? ¿Cómo get el nombre de location (dirección) del dispositivo a partir de este valor de latitud y longitud? por favor, ayúdame

Gracias por adelantado

He intentado esto:

- (void)viewDidLoad { [super viewDidLoad]; LocationManager = [[CLLocationManager alloc]init]; LocationManager.delegate=self; LocationManager.desinetworkingAccuracy = kCLLocationAccuracyBest; [LocationManager startUpdatingLocation]; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSString * latitude = [[[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.latitude]autorelease]; NSString * longitude = [[[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.longitude]autorelease]; [LocationManager stopUpdatingLocation]; NSLog(@"latitude:%@",latitude); NSLog(@"longitude:%@",longitude); } 

  -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { [manager stopUpdatingLocation]; lati = [[NSString alloc] initWithFormat:@"%+.6f", newLocation.coordinate.latitude]; NSLog(@"address:%@",lati); longi = [[NSString alloc] initWithFormat:@"%+.6f", newLocation.coordinate.longitude]; NSLog(@"address:%@",longi); [geoCoder reverseGeocodeLocation: newLocation completionHandler: ^(NSArray *placemarks, NSError *error) { //Get nearby address CLPlacemark *placemark = [placemarks objectAtIndex:0]; //String to hold address NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]; //Print the location to console NSLog(@"I am currently at %@",locatedAt); address = [[NSString alloc]initWithString:locatedAt]; NSLog(@"address:%@",address); }]; } 
 CLGeocoder *ceo = [[CLGeocoder alloc]init]; CLLocation *loc = [[CLLocation alloc]initWithLatitude:32.00 longitude:21.322]; [ceo reverseGeocodeLocation: loc completionHandler: ^(NSArray *placemarks, NSError *error) { CLPlacemark *placemark = [placemarks objectAtIndex:0]; NSLog(@"placemark %@",placemark); //String to hold address NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]; NSLog(@"addressDictionary %@", placemark.addressDictionary); NSLog(@"placemark %@",placemark.region); NSLog(@"placemark %@",placemark.country); // Give Country Name NSLog(@"placemark %@",placemark.locality); // Extract the city name NSLog(@"location %@",placemark.name); NSLog(@"location %@",placemark.ocean); NSLog(@"location %@",placemark.postalCode); NSLog(@"location %@",placemark.subLocality); NSLog(@"location %@",placemark.location); //Print the location to console NSLog(@"I am currently at %@",locatedAt); }]; 

Tienes que hacer una location inversa. Tienes suerte: Apple proporciona una class para hacerlo. Ver CLGeocoder (para iOS> = 5.0) o MKReverseGeocoder (para iOS <5.0)

Puede usar la API de Google Maps para esto (funciona en cualquier iOS):

 NSString *req = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%.5f,%.5f&sensor=false&language=da", location.latitude, location.longitude]; NSString *resultString = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL]; 

Luego puede analizar esta respuesta a NSDictionary usando cualquier biblioteca JSON (SBJSON en este caso):

 SBJSON *jsonObject = [[SBJSON alloc] init]; NSError *error = nil; NSDictionary *response = [jsonObject objectWithString:resultString error:&error]; [jsonObject release]; 

Dirección de extracción:

 if (error) { NSLog(@"Error parsing response string to NSObject: %@",[error localizedDescription]); }else{ NSString *status = [response valueForKey:@"status"]; if ([status isEqualToString:@"OK"]) { NSArray *results = [response objectForKey:@"results"]; int count = [results count]; //NSSLog(@"Matches: %i", count); if (count > 0) { NSDictionary *result = [results objectAtIndex:0]; NSString *address = [result valueForKey:@"formatted_address"]; } } } 

Tienes que crear un object CLLocation y pasar eso para invertirGeoCoder .

Antes de iOS 5.0 tenemos la class MKReverse Geo-coder para encontrar esto … Ahora está en desuso.

Tenemos que usar la class CLGeocoder en Core Location Framework