【发布时间】:2016-05-16 09:25:07
【问题描述】:
我在单击按钮时进行了反向地理编码,使用 CLLocationManagerDelegate 工作正常。但是现在我从用户那里取了一个 UISearchBar 来取地名,点击按钮时我想显示用户输入的地方和上面的标记。 由于地理编码需要一些时间,因此没有值存储在位置中,但应用程序完成了它的工作。 那么谁能告诉我该怎么做?如果我在任何地方错了,请纠正我。
- (IBAction)searchLocation:(id)sender {
NSString *address = self.searchBar.text;
NSLog(@"%@",address);
[forwardGeocoder geocodeAddressString:address completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if ([placemarks count]>0) {
CLPlacemark *placeMarkForward = [placemarks objectAtIndex:0];
locationValue = placeMarkForward.location;
NSLog(@"Location : :%@",locationValue);
}
}];
[reverseGeocoder reverseGeocodeLocation:locationValue completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if (error == nil && [placemarks count]>0) {
CLPlacemark *placeMarkReverse = [placemarks lastObject];
CLLocation *currentLocation;
marker.position = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
marker.title = [NSString stringWithFormat:@"%@",placeMarkReverse.country];
marker.snippet = [NSString stringWithFormat:@"%@\n%@", placeMarkReverse.locality,placeMarkReverse.postalCode];
marker.map = mapView_;
}
}];
}
【问题讨论】:
标签: ios objective-c google-maps geocoding core-location