【问题标题】:Geocoder cannot update address using while changing latitude and longitude地理编码器在更改纬度和经度时无法更新地址
【发布时间】:2016-05-17 11:20:05
【问题描述】:

每次我移动地图时它都会进入 onLocationChanged 块,并且还会获取新的纬度和经度,但它不会更新地址,而是显示第一次加载的地址。我正在使用以下内容来更新地址:

@Override
public void onLocationChanged(Location location) {

    Log.e("change" , "change");

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

    try {
        Geocoder geo = new Geocoder(this, Locale.getDefault());
        List<Address> addresses = geo.getFromLocation(latitude, longitude, 1);
        if (addresses.isEmpty()) {

            Log.e("TAG", "Waiting for Location");
        }
        else {
            if (addresses.size() > 0) {
                Log.e("TAG", addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() + ", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName());
                //yourtextfieldname.setText(addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName());
                //Toast.makeText(getApplicationContext(), "Address:- " + addresses.get(0).getFeatureName() + addresses.get(0).getAdminArea() + addresses.get(0).getLocality(), Toast.LENGTH_LONG).show();
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace(); // getFromLocation() may sometimes fail
    }
}

【问题讨论】:

  • 您已经评论了更新 textview 上的文本的行!
  • 我那里还有一个日志
  • 你看到logcat中的日志了吗?
  • 是的,我确实看到了日志
  • 它记录了什么?

标签: android google-maps


【解决方案1】:

Geocoder 在某些设备中不可用,请使用 Google API Client 代替 Geocoder

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多