2

我们正在为 UIMapView 设置地址搜索的地理编码,但我们面临的问题是添加新地址时:搜索地址时,还应该有一个自动完成。在搜索栏上怎么可能?(就像我们在网上搜索城市列表如果我们搜索浦那然后显示所有与 P 相关的城市名称。)请解决任何人?

谢谢你!

4

1 回答 1

0

您必须尝试这种方法。此方法使用苹果服务器进行地理编码。有时苹果服务器提供比谷歌更好的响应。很快(在 IOS 6.1 中)谷歌地图将完全脱离 IOS。因此,如果应用程序留在苹果提供的功能中,那就太好了。

-(void)searchBarSearchButtonClicked:(UISearchBar *)theSearchBar
{
    [theSearchBar resignFirstResponder];
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:theSearchBar.text completionHandler:^(NSArray *placemarks, NSError *error) {
        //Error checking

        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        MKCoordinateRegion region;
        region.center.latitude = placemark.region.center.latitude;
        region.center.longitude = placemark.region.center.longitude;
        MKCoordinateSpan span;
        double radius = placemark.region.radius / 1000; // convert to km

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

        region.span = span;

        [theMapView setRegion:region animated:YES];
    }];
}
于 2013-03-18T05:49:20.187 回答