0
我想獲取用戶位置使用GPS,但我需要轉換lat和long來解決,但geocoder不斷給出錯誤gc是未定義的。地理編碼器未定義?
public class MyLocationListener implements LocationListener{
public void onLocationChanged(Location loc){
try{
Geocoder gc = new Geocoder(this, Locale.ENGLISH);
List <Address> addr = gc.getFromLocation(loc.getLatitude(),loc.getLongitude(),1);
if (addr != null && addr.size() > 0){
Address address = addr.get(0);
String results = address.getAddressLine(0);
Toast.makeText(getApplicationContext(),results,Toast.LENGTH_LONG).show();
}
}catch(Exception e){
}
}
嗨,已經導入,有沒有在下面的代碼中的錯誤? – 2012-07-24 09:12:21
使用地理編碼器gc = new Geocoder(yourActivityname.this,Locale.ENGLISH); – Shalini 2012-07-24 09:29:39
您好,我宣佈的結果會返回地址名稱還是街道名稱? – 2012-07-24 10:21:26