2011-06-30 74 views
0

我一直無法在模擬器上測試我的代碼,因爲我明白您無法在模擬器上使用地理定位。因此我不確定是否正確初始化/使用函數實用程序。使用Android地理位置定位工具

(我要來地理定位我的手機,並通過TextView打印最近的已知地址到我的緯度/經度修復)

繼承人我的代碼:

Location location; 
Geocoder geocoder; 
TextView Address; 

private OnClickListener OnClick = new OnClickListener(){ 
    public void onClick (View src){ 

     double latitude = location.getLatitude(); 
     double longitude = location.getLongitude(); 

     if (longitude != 0 && latitude != 0){ 
      try { 
       List<Address> list = geocoder.getFromLocation(latitude, longitude, 1); 
       Address address = list.get(0);   
       StringBuilder sb = new StringBuilder(); 
       sb.append(address); 
       String addressString = sb.toString(); 
       Address.setText(addressString); 
      } catch (IOException e) {} 
     } 
    } 
}; 

回答