ios - 以编程方式插入纬度和经度以进行反向地理定位

标签 ios objective-c cllocationmanager

我有一种情况,我从 XML 文件中提取纬度和经度,解析并显示它。并且我成功地能够在两个不同的 UILabels 中执行此操作。但现在我需要位置并显示它有人可以建议我如何实现这一点吗?我有这段代码,但它只能让我从模拟器中选择坐标值。

- (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 解析无关。

最佳答案

试试这个

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

}];

关于ios - 以编程方式插入纬度和经度以进行反向地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16975319/

相关文章:

ios - 两个日期之间经过的天数总是相差一天

iphone - linkedin Oauth如何记住登录

ios - 生成随机字母字符串的有效方法?

从模拟器关闭应用程序时的 iOS 调试位置监控

iphone - 具有自定义 UI 的 iSpeech SDK

iphone - 无法通过应用程序加载器提交

iphone - 通过使用低分辨率图像然后交换高分辨率图像来加速 UIImagePickerController

iphone - 我的应用程序仅请求推送通知权限,但不请求位置。我该如何解决这个问题?

ios - 为什么我更新的应用程序在启动时仅适用于 IOS8 崩溃?

ios - UIActivityView 将文件附加到电子邮件