- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 MKReverseGeocoder
和 locationManager 的
didUpdateToLocation
委托(delegate) 但是我想知道当我在 设备
。
我的代码如下:-
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
[super viewDidLoad];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// this creates a MKReverseGeocoder to find a placemark using the found coordinates
reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSLog(@"MKReverseGeocoder has failed.");
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
MKPlacemark * myPlacemark = placemark;
NSString *city = myPlacemark.thoroughfare;
NSString *subThrough=myPlacemark.subThoroughfare;
NSString *locality=myPlacemark.locality;
NSString *subLocality=myPlacemark.subLocality;
NSString *adminisArea=myPlacemark.administrativeArea;
NSString *subAdminArea=myPlacemark.subAdministrativeArea;
NSString *postalCode=myPlacemark.postalCode;
NSString *country=myPlacemark.country;
NSString *countryCode=myPlacemark.countryCode;
NSLog(@"city%@",city);
NSLog(@"subThrough%@",subThrough);
NSLog(@"locality%@",locality);
NSLog(@"subLocality%@",subLocality);
NSLog(@"adminisArea%@",adminisArea);
NSLog(@"subAdminArea%@",subAdminArea);
NSLog(@"postalCode%@",postalCode);
NSLog(@"country%@",country);
NSLog(@"countryCode%@",countryCode);
}
输出
cityDrive-in Road
subThrough(null)
地区(空)
subLocality(null)
adminisAreaGujarat
subAdminArea(null)
postalCode(null)
国家/地区印度
国家代码IN
使用 CLGeocoder
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// this creates a MKReverseGeocoder to find a placemark using the found coordinates
// reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
// reverseGeocoder.delegate = self;
// [reverseGeocoder start];
CLGeocoder *reverseGeo = [[CLGeocoder alloc] init];
[reverseGeo reverseGeocodeLocation: newLocation completionHandler:
^(NSArray *placemarks, NSError *error) {
NSLog(@"%@",[placemarks objectAtIndex:0]);
for (CLPlacemark *placemark in placemarks) {
NSLog(@"~~~~~~~~%@",placemark.locality);
}
}];
}
输出是:- ~~~~~~~~(null)
我上面的代码在模拟器中正常工作但在设备中不正常.. :( 请帮助并指导我以正确的方式获取城市名称
最佳答案
你真的不应该使用 MKReverseGeocoder 因为它已经被苹果在 iOS5 中贬值了,你真的应该使用 CLGeocoder。 CLGeocode 将返回基于 NSArray *placemarks 的信息,然后您可以遍历它们并调用 assoc 数组中的键。请通过链接。
关于iphone:- MKReverseGeocoder 获取 postalCode、subAdministrativeArea、locality 和 subThoroughfare 的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13723825/
在我的应用程序中,我正在创建自己的地标,我需要将街道编号与街道名称分开。但是我看不出如何使用地址字典初始化 MKPlacemark 以便在 subThoroughfare 属性中返回街道号码,因为没有
当注销或发送(使用 RestKit 的 Web 服务)时,特别是 CLPlacemark 的 subThoroughfare 属性出现奇怪的字符,我希望连字符出现。 记录: NSLog(@"%@",
我正在使用 MKReverseGeocoder 和 locationManager 的 didUpdateToLocation 委托(delegate) 但是我想知道当我在 设备。 我的代码如下:-
我是一名优秀的程序员,十分优秀!