gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:19:48 28 4
gpt4 key购买 nike

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

@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
}
}

最佳答案

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

关于android - 更改纬度和经度时,地理编码器无法使用更新地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37274639/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com