2013-03-18 41 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