我的代码:
try
{
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(LocationActivity.this, Locale.getDefault());
addresses = geocoder.getFromLocation(longitude,latitude,1);
Toast.makeText(LocationActivity.this, addresses.size() + "", Toast.LENGTH_LONG).show();
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(0);
String country = addresses.get(0).getAddressLine(0);
Toast.makeText(LocationActivity.this, address + " " + city + " " + country, Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(LocationActivity.this,e.toString(), Toast.LENGTH_LONG).show();
}
这是我从经度和纬度获取地址的代码。 但每次addresses.size返回0
谁能帮我解决这个问题
最佳答案
我找到了解决方案...
在 getFromLocation()
上按住 Ctrl
并转到 Geocoder.class
。
然后下载 Android API 的源代码并重新启动您的项目。
然后你就会看到它的工作
关于android - geocoder.getFromLocation 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12778295/