2016-07-22 22 views
0

我想要做一個獲取當前地址的應用程序;國家名稱,城市名稱和地區名稱。然後,我有3名使用土耳其語的所有國家名稱,城市名稱和地區名稱的微調者。來自Geocoder的地址是英文

當我使用GPS和Geocoder獲取地址時,我想將它們與我的紡紗器中的名稱進行匹配。

的問題是從地理編碼器傳來的地址是英文的。所以,這與我的微調國家不匹配。所以我不能用編程方式選擇真正的國家。

這裏是我相關的代碼:

//In here I add countries coming from web service into countries array. 
for(int i=0;i<responseInfo.size();i++) { 
    String name = responseInfo.get(i).getName(); 
    countries.add(name); 
    //If country name is equals to country name coming from gps 
    //then I hold it in selectedCountry variable. 
    //But "Turkey" != "Türkiye" so this if block does not work 
    if(name.equalsIgnoreCase(foundAddress.getCountryName())) 
    { 
     selectedCountryId = (String)responseInfo.get(i).getId(); 
     selectedCountry = responseInfo.get(i); 

    } 
} 

//In this method, when I get country name from the item in addresses array 
//it returns in English 
public List<Address> findAddressFromLatLng(double latitude, double longitude) 
{ 
    Geocoder geocoder; 
    List<Address> addresses = null; 
    geocoder = new Geocoder(this, Locale.getDefault()); 
    try { 
     addresses = geocoder.getFromLocation(latitude, longitude, 1); 

    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    if ((addresses != null) && (addresses.size() != 0)) { 
     return addresses; 
    } 
    return null; 
} 

在另一個裝置,我沒有問題。國家名稱從地理編碼器來爲土耳其(這意味着地理編碼有土耳其的名字也)。可能是因爲設備語言。

我試圖改變這一行,但我無法找到的土耳其語言環境:提前

geocoder = new Geocoder(this, Locale.getDefault()); 

感謝。

回答

2

文檔爲Geocoder建議設置一個Locale是你所需要的東西。土耳其沒有預定義的Locale,但您可以輕鬆定義一個:

Locale locale = new Locale("tr", "TR"); 
+0

謝謝!這正是我需要=) – Hilal

+0

不客氣! – Egor