2012-05-23 56 views
1

我在我的應用中實現了反向地理編碼,它正在工作,但有時會發生一個非常奇怪的問題。反向地理編碼問題

的代碼是

  List<Address> addresses = geo.getFromLocation(
        obj.getLatitude(), obj.getLongitude(), 1); 


      List<Address> address = geo.getFromLocationName(addresses.get(0).getLocality().getBytes() , 1); 


      Address location = address.get(0); 

在第一部分中,我得到在我的地方的地址對象。比我想恢復城市的通用座標在我所在的位置,因爲我不想存儲我確切位置的座標。

這是工作,但我遇到了一個很奇怪的問題!嘗試使用假貨應用程序的應用程序,我在「Ñuñoa」中設置自己的位置,第一個地址找到了正確的位置,但是當我嘗試獲取通用座標時,我得到的不是智利,而是祕魯的「Nunoa」! ! 這沒有任何意義!爲什麼這個?

感謝您的幫助

+0

我解決了!當您使用android api並且只輸入城市名稱時,Google會檢索結果中列出的第一個城市名稱!我解決了它創建一個字符串,它是obj.getLocality()+「,」+ obj.getAdminArea()的串聯。 – michoprogrammer

+0

可以發佈你的完整代碼嗎? – swathi

回答

0

當然Swathi。

List<Address> addresses = geo.getFromLocation(msg_r.getLatitude(), 
       msg_r.getLongitude(), 1); 
     String geoL = addresses.get(0).getLocality() + ", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode(); 

       // reverse-reverseGeocoding 
       List<Address> address = geo.getFromLocationName(geoL, 1); 

       System.out.println("Where I am? " + geoL); 
       Address location = address.get(0); 

       // generic coordinate for the locality/city/town 
       location.getLatitude(); 
       location.getLongitude();