ios - Mapview显示错误的搜索结果

标签 ios mkmapview

我正在使用iOS MapView。每当我搜索一个地方时,它都会给出令人惊讶的错误结果。

如果我搜索“必胜客”,则会带我到日本。如果我搜索拉尔巴格,它将带我到比哈尔邦的巴特那。对于UB City,它将带我前往美国。

你能帮我么?

这是要搜索的代码。

_geocoder = [[CLGeocoder alloc] init];
            [_geocoder geocodeAddressString:textField.text completionHandler:^(NSArray *placemarks, NSError *error) {
                //Error checking
                [Utility hideProgressHUD];
                CLPlacemark *placemark = [placemarks objectAtIndex:0];
                MKCoordinateRegion region;
                region.center = [(CLCircularRegion *)placemark.region center];
//                region.center.latitude = placemark.region.center.latitude;
//                region.center.longitude = placemark.region.center.longitude;
                MKCoordinateSpan span;
                double radius = [(CLCircularRegion *)placemark.region radius] / 1000; // convert to km

                NSLog(@"[searchBarSearchButtonClicked] Radius is %f", radius);
                span.latitudeDelta = radius / 112.0;

                region.span = span;

                [_mapView setRegion:region animated:YES];
            }];

最佳答案

尝试这个,

NSString *location = @"some address, state, and zip";
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
                [geocoder geocodeAddressString:location 
                     completionHandler:^(NSArray* placemarks, NSError* error){
                         if (placemarks && placemarks.count > 0) {
                             CLPlacemark *topResult = [placemarks objectAtIndex:0];
                             MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];

                             MKCoordinateRegion region = self.mapView.region;
                             region.center = placemark.region.center;
                             region.span.longitudeDelta /= 8.0;
                             region.span.latitudeDelta /= 8.0;

                             [self.mapView setRegion:region animated:YES];
                             [self.mapView addAnnotation:placemark];
                         }
                     }
                 ];

我在我的一个应用程序中使用了上面的代码,在iOS8中对我来说效果很好。

关于ios - Mapview显示错误的搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34133000/

相关文章:

iPhone MKMapView注释聚类

xcode - MKMapView setRegion : animated: crashes the app (edited)

ios - 适用于iOS模拟器的IBM-Bluemix Push Service构建失败

ios - 将 IndexPath 行值传递给委托(delegate)函数而不是 Sender.tag 以删除图像项目 CollectionView Swift

iphone - 如何获取沙盒中文档的所有文件名?

ios - 如何以编程方式删除 UITableView 的第 0 行?

ios - 需要在 IOS 的 mapview 上添加一个固定的叠加层

iPhone MKMapView 商业应用?

ios - MKMapView 中的动画标题更改

ios - 使用 swiftvalidator 时,类 'AppDelegate' 的重复接口(interface)定义错误和属性有先前的声明错误