Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改纬度和经度时,地理编码器无法使用更新地址_Android_Google Maps - Fatal编程技术网

Android 更改纬度和经度时,地理编码器无法使用更新地址

Android 更改纬度和经度时,地理编码器无法使用更新地址,android,google-maps,Android,Google Maps,每次我移动地图时,它都会进入onLocationChanged块,同时也会获取新的latitude和long,但它不会更新地址,而是显示第一次加载的地址。我正在使用以下内容更新地址: @Override public void onLocationChanged(Location location) { Log.e("change" , "change"); double latitude = location.getLatitude(); double longit

每次我移动地图时,它都会进入onLocationChanged块,同时也会获取新的latitude和long,但它不会更新地址,而是显示第一次加载的地址。我正在使用以下内容更新地址:

@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
    }
}
@覆盖
已更改位置上的公共无效(位置){
Log.e(“变更”、“变更”);
双纬度=location.getLatitude();
double longitude=location.getLongitude();
试一试{
Geocoder geo=新的Geocoder(这个,Locale.getDefault());
列表地址=geo.getFromLocation(纬度,经度,1);
if(addresses.isEmpty()){
Log.e(“标签”、“等待位置”);
}
否则{
如果(地址.size()>0){
Log.e(“标记”、地址.get(0).getFeatureName()+”、“+地址.get(0).getLocality()+”、“+地址.get(0).getAdminArea()+”、“+地址.get(0).getCountryName());
//yourtextfieldname.setText(地址.get(0).getFeatureName()+”,“+地址.get(0).GetLocation()+”,“+地址.get(0).getAdminArea()+”,“+地址.get(0).getCountryName());
//Toast.makeText(getApplicationContext(),“Address:-”+addresses.get(0).getFeatureName()+addresses.get(0).getAdminArea()+addresses.get(0).getLocality(),Toast.LENGTH_LONG).show();
}
}
}
捕获(例外e){
e、 printStackTrace();//getFromLocation()有时可能会失败
}
}

Geocoder在某些设备中不可用,请使用Google API客户端而不是Geocoder

您已经对textview上更新文本的行进行了注释!我仍然有一个日志,你在logcat中看到日志了吗?是的,我看到了日志,它记录了什么?如何使用它?你能帮我通过这个链接吗,它会帮助你的