2013-03-18 70 views
2

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

谢谢!

+0

http://stackoverflow.com/questions/2077404/autocomplete-search-example-for-iphone和http://stackoverflow.com/questions/14601936/how-to-highlight-search-string- in-autocomplete-results-for-ios5和http://stackoverflow.com/questions/2281798/how-to-search-mkmapview-with-uisearchbar – iPatel 2013-03-18 05:40:38

回答

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]; 
    }]; 
} 
+0

此代码搜索Lat,long,place&Radius我的问题是auto (如果你打开Goog​​le页面(API)并搜索任何相关的字母(就像我这样显示相关的列表)自动完成) – 2013-03-18 07:01:21

+0

我明白了。等一下。我会为你提供更好的解决方案。 – 2013-03-18 07:09:51