2011-06-25 21 views
2

我試圖找經緯度&長從用戶給出的地址,我使用下面的代碼,Android的問題得到經緯度從給定的地址

GeoPoint pointForEnterAddr; 


try { 

    List<Address> address = coder.getFromLocationName(enterAddr, 1); 

        if (address == null) 

        pointForEnterAddr = null; 

        else { 
         Address location = address.get(0); 
         System.out.println("Lat in button click :" 
           + location.getLatitude()); 
         System.out.println("Long in button click :" 
           + location.getLongitude()); 


pointForEnterAddr = new GeoPoint((int) (location.getLatitude() * 1E6), 
        (int) (location.getLongitude() * 1E6)); 


} 
catch (Exception ex) { 
        System.out.println("Error here :" + ex); 
       } 

但每次它來捕捉部分&節目例外, java.io.IOException:服務不可用

我該如何解決並獲得正確的輸出?請告訴我。

謝謝

回答

0

剛提替代方案,您可以使用谷歌地圖基於REST的reverse geocoder。你可以用這個作爲後備。由於您在應用中也會使用Google地圖,因此您應該熟悉API規則。

+0

這不完全正確。如果您不使用給定的方法,則與從某個隨機服務器調用API相同,這意味着您受到每日通話次數的限制。 – thedp

相關問題