我遇到的问题是,如果我尝试使用geocoder.getFromLocationName(" California",1)函数获取地址,它会找到地址,但如果我在我的设备上测试它(小米Mi5,奥利奥)它返回一个空列表。
提前致谢!
private void geoLocate(){
Log.d(TAG, "geoLocate: geolocating");
String searchString = mSearchText.getText().toString();
Log.d(TAG, "geoLocate: Searching for " + searchString);
Geocoder geocoder = new Geocoder(this);
List<Address> list = new ArrayList<>();
try{
if(geocoder.isPresent()){
list = geocoder.getFromLocationName(searchString,1);
} else{
Log.d(TAG, "geoLocate: GEOCODER IS NOT PRESENT");
}
}catch (IOException e){
Log.e(TAG, "geoLocate: IOException " + e.getMessage() );
}
if(list.size() > 0 ){
Address address = list.get(0);
Log.d(TAG, "geoLocate: found a location: " + address.toString());
}else{
Log.d(TAG, "geoLocate: Location not found");
}
}
答案 0 :(得分:0)
您是否已在手机上获得了应用程序的位置许可? 如果没有..转到yourapp&gt;&gt;权限&gt;&gt;&gt; locationPermission ...