【问题标题】:Mapview showing wrong search resultsMapview 显示错误的搜索结果
【发布时间】:2015-12-07 11:56:41
【问题描述】:

我正在使用 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];
            }];

【问题讨论】:

    标签: ios mkmapview


    【解决方案1】:

    试试这个,

    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 中运行良好。

    【讨论】:

    • 可能有效,但我们不能要求用户以相同的模式进行搜索。用户只需键入一个位置。顺便问一下,有多少个邮政编码有人能准确记住?
    • 在这种情况下,您可以避免提供邮政编码并尝试使用街道名称或特定区域,它会为您工作,但提供邮政编码可以帮助geocoder 找到更准确的结果。
    • 从最终用户的角度思考。作为普通用户,没有人会使用街道名称、州、国家或其他任何内容进行搜索。他将简单地搜索一个关键字。如果用户想要搜索“咖啡日”怎么办。他会简单地说咖啡日。他不会提及任何街道。用户的意图是搜索其当前位置附近的 Coffee Days。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2016-06-26
    相关资源
    最近更新 更多