0

我有一个情况,我从 XML 文件中提取纬度和经度,解析和显示它。我成功地能够在两个不同的 UILabel 中做到这一点。但现在我需要位置并将其显示在标签中. 有人可以建议我如何实现这一点,我有这个代码,但它只能让我从模拟器中选择坐标值。

- (IBAction)geoCodeLocation:(id)sender{

 //Geocoding Block
[self.geoCoder reverseGeocodeLocation: locationManager.location 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);

     //Set the label text to current location
     [locationLabel setText:locatedAt];

 }];
}

建议:这个问题不是关于 XML 解析的。

4

1 回答 1

1

尝试这个

 CLLocation *location = [[CLLocation alloc] initWithLatitude:37.78583400      longitude:-122.40641700];

[self.geoCoder reverseGeocodeLocation: location completionHandler: 
^(NSArray *placemarks, NSError *error) {

 //Get nearby address
 CLPlacemark *placemark = [placemarks objectAtIndex:0];

 //String to hold address
 locatedAtcountry = placemark.country;
 locatedAtcity = placemark.locality;
 locatedAtisocountry = placemark.ISOcountryCode;

 //Print the location to console
 NSLog(@"Estas en %@",locatedAtcountry);
 NSLog(@"Estas en %@",locatedAtcity);
 NSLog(@"Estas en %@",locatedAtisocountry);

 [cityLabel setText:[NSString stringWithFormat:@"%@",locatedAtcity]];
 [locationLabel setText:[NSString stringWithFormat:@"%@",locatedAtcountry]];

 //Set the label text to current location
 //[locationLabel setText:locatedAt];

}];
于 2013-06-07T05:26:25.300 回答