NSString *oreillyAddress = @"南昌深圳市场";
CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];
[myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *places, NSError *error) {
if ([places count] > 0 && error == nil) {
NSLog(@"Found %lu place(s).", (unsigned long)[places count]);
CLPlace *firstPlace = [places objectAtIndex:0];
NSLog(@"Longitude = %f", firstPlace.location.coordinate.longitude);
NSLog(@"Latitude = %f", firstPlace.location.coordinate.latitude);
}
else if ([places count] == 0 && error == nil) {
NSLog(@"Found no places.");
} else if (error != nil) {
NSLog(@"An error occurred = %@", error);
}
}];
float kilometres =50.00;
CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];
[myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *places, NSError *error) {
if ([places count] > 0 && error == nil) {
NSLog(@"Found %lu place(s).", (unsigned long)[places count]);
CLPlace *firstPlace = [places objectAtIndex:0];
NSLog(@"Longitude = %f", firstPlace.location.coordinate.longitude);
NSLog(@"Latitude = %f", firstPlace.location.coordinate.latitude);
}
else if ([places count] == 0 && error == nil) {
NSLog(@"Found no places.");
} else if (error != nil) {
NSLog(@"An error occurred = %@", error);
}
}];
float kilometres =50.00;
float kilometres =50.00;
NSString *oreillyAddress = @"南昌深圳农批市场";
CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];
[myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *places, NSError *error) {
if ([places count] > 0 && error == nil) {
NSLog(@"Found %lu place(s).", (unsigned long)[places count]);
CLPlace *firstPlace = [places objectAtIndex:0];
NSLog(@"Longitude = %f", firstPlace.location.coordinate.longitude);
kilometres = firstPlace.location.coordinate.longitude;
NSLog(@"Latitude = %f", firstPlace.location.coordinate.latitude);
}
else if ([places count] == 0 && error == nil) {
NSLog(@"Found no places.");
} else if (error != nil) {
NSLog(@"An error occurred = %@", error);
}
}];
NSLog(@"kilometres %@", kilometres );这样的话在还未执行完block,kilometres 直接输出为null了