[英]CLGeocoder not working
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[window addViewForTouchPriority:viewController.view];
if(self.locationManager==nil){
locationManager=[[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.purpose = @"We will try to tell you where you are if you get lost";
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=500;
self.locationManager=locationManager;
}
geoCoder = [[CLGeocoder alloc] init];
if([CLLocationManager locationServicesEnabled]){
[self.locationManager startUpdatingLocation];
}
return YES;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
lati = [[NSString alloc] initWithFormat:@"%+.6f", newLocation.coordinate.latitude];
NSLog(@"address:%@",lati);
longi = [[NSString alloc] initWithFormat:@"%+.6f", newLocation.coordinate.longitude];
NSLog(@"address:%@",longi);
CLLocationCoordinate2D coord;
coord.latitude = [lati doubleValue];
coord.longitude = [longi doubleValue];
[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);
}];
}
I am using above code to get address by giving latitude and longitude, but control is not entering in to geocoder method, it skips it. 我正在使用上面的代码通过提供纬度和经度来获取地址,但是控件没有输入到geocoder方法中,因此跳过了它。 Can anybody help me in it. 有人可以帮我吗?
Thanks in advance. 提前致谢。
没关系,控件不输入方法,但可以,请注意输出将起作用。
that is normal, because the code inside the reverseGeocodeLocation is execute inside a block. 这是正常的,因为reverseGeocodeLocation内部的代码是在一个块内执行的。 The execution of the code inside a block occurs in another thread, so is not execute in the main thread, that's why the control don't enter inside the geocoder method. 块内代码的执行发生在另一个线程中,因此不在主线程中执行,这就是为什么控件不进入geocoder方法内部的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.