2015-05-14 14 views
0

假設以下情況:
用戶從列表中選擇一個國家。點擊國家後,地圖應放大到所選國家。如何使用OSMDroid縮放到特定國家?

如何在OSMDroid中實現zoomToCountry如果我只知道列表中的國家名稱?

在PHP API 「谷歌地圖V3」 有像

function findAddress(address) { 
     var geocoder = null; 
     geocoder = new google.maps.Geocoder(); 

     if (!address) 
     var address=document.getElementById("countryselect").value; 
     if ((address != '') && geocoder) { 
      geocoder.geocode({ 'address': address}, function(results, status) { 
      if (status == google.maps.GeocoderStatus.OK) { 
       if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { 
       if (results && results[0] && results[0].geometry && results[0].geometry.viewport) 
        map.fitBounds(results[0].geometry.viewport); 
       } else { 
       alert("No results found"); 
       } 
      } else { 
       alert("Geocode was not successful for the following reason: " + status); 
      } 
      }); 
     } 
    } 

的解決方案是否有OSMDroid或OSMBonuspack任何類似的?

回答

0

PHP解決方案是使用國家/地區名稱呼叫地理編碼服務,以獲取國家/地區邊界框。

您可以使用Nominatim服務來做類似的事情。所以OSMBonusPack GeocoderNominatim應該可用。

大致那(沒有錯誤處理,的AsyncTask等):

GeocoderNominatim coder = new GeocoderNominatim(ctx); 
List<Address> results = coder.getFromLocationName(countryName, 1); 
Address address = results.get(0); 
Bundle extras = address.getExtras(); 
BoundingBoxE6 bb = extras.getParcelable("boundingbox"); 

然後:

mapView.zoomToBoundingBox(bb); 

就這麼簡單PHP /谷歌地圖的解決方案,是嗎?

+0

Th錯誤符合:GeocoderNominatim coder = new GeocoderNominatim(context); ** **找不到。**帶有按鈕** Edit Source Lookup Path ... **抱歉,我是android新手。 Thx尋求幫助 – Sebastian

+0

將gson-2.3.1,jar添加到構建路徑後工作正常! (http://mvnrepository.com/artifact/com.google.code.gson/gson/2.3.1) – Sebastian

+0

安裝指南中提到了對GSON的需求。你的意思是說你根本沒有gson,或者你必須用gson-2.3.1.jar替換gson-2.2.4.jar? – MKer