如何在iPhone中获取设备位置名称?

Sam*_*mar 3 iphone gps location ios

目前我在iPhone应用程序中工作,使用CLLocationManager获取纬度和经度值.我不知道这个?如何从此纬度和经度值获取设备位置(地址)名称?请帮我

提前致谢

我试过这个:

- (void)viewDidLoad
{
    [super viewDidLoad];

    LocationManager = [[CLLocationManager alloc]init];
    LocationManager.delegate=self;
    LocationManager.desiredAccuracy = 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);
}
Run Code Online (Sandbox Code Playgroud)

iPh*_*lly 5

    -(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);
     }];

}
Run Code Online (Sandbox Code Playgroud)


App*_*ate 5

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);



      }];
Run Code Online (Sandbox Code Playgroud)