我正在尝试使用 GPS 获取用户位置,但我需要将经纬度转换为地址,但地理编码器不断给出错误 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){
}
}