我有一个情况,我从XML文件中提取纬度和经度,解析并显示它。我成功地能够在两个不同的UILabel中完成它。但现在我需要位置和显示它在Label.Can有人建议我如何实现这一点,我有这个代码,但它只允许我从模拟器中选择坐标值。
- (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解析无关。
答案 0 :(得分: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];
}];