Mapview显示错误的搜索结果

时间:2015-12-07 11:56:41

标签: ios mkmapview

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

如果我搜索必胜客'它带我到日本。如果我搜索Lalbagh,它会把我带到比哈尔邦的巴特那。对于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];
            }];

1 个答案:

答案 0 :(得分:0)

试试这个,

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中对我来说很好。