2016-04-03 130 views
-1

我正在使用地理編碼器來獲取lat和long在我的android應用程序。有些時候它工作得很好,但現在它停止工作。我沒有更改代碼。爲什麼這很受歡迎?Geocoder突然停止工作

public void onItemClick(AdapterView adapterView, View view, int position, long id) { 
     String str = (String) adapterView.getItemAtPosition(position); 
    List<Address> addressList= null; 
      if(str != null || str.equals("")){ 
       Geocoder geocoder = new Geocoder(this); 
       try { 
        addressList = geocoder.getFromLocationName(str, 1); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       Address address = addressList.get(0); 
       //LatLng latLng = new LatLng(address.getLatitude(),address.getLongitude()); 
       Intent i = new Intent(Activity2.this, MainActivity.class); 
       i.putExtra("location", str); 
       i.putExtra("latitude", address.getLatitude()); 
       i.putExtra("longitude", address.getLongitude()); 
       startActivity(i); 
      } 
} 

謝謝!

+0

爲什麼有人會投票?至少告訴我們我們要去哪裏錯了? – user3304748

+0

此通話需要Internet連接。當它不工作時你有互聯網連接嗎? –

+0

雅我有互聯網連接。 7-8小時前它工作正常。 – user3304748

回答

0

您是否在收到IOException: Timed out waiting for response from server錯誤?因爲我已經看過其他帖子,提到Geocoder不能正常運行,即使它早些時候(幾小時/幾天前)也能正常運行。我去了公共門票 - https://code.google.com/p/gmaps-api-issues/issues/detail?id=9153 - 這是去年1月發生的,而且似乎還有其他人正在經歷這種情況。你提到你沒有修改代碼中的任何東西,對吧?