【发布时间】:2019-09-26 19:31:14
【问题描述】:
这是我的程序的要点。当我按下用于告诉位置的按钮时,如果地理编码器没有抛出任何异常,它工作正常,但是当地理编码器抛出异常并且同时我的应用程序停止一些时,问题就出现了时间就像它挂起一样。
因为进度条停止旋转,也没有按下停止按钮。但是在 30 秒或 1 分钟后打印:
没有找到地址……
谁能帮我解决这个问题……提前谢谢你。
这是在 onCreate 方法中:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,3, this);
//分离方法:
public void geo(double latitude,double longitude)
{
if(Geocoder.isPresent())
{
try
{
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
if(null!=listAddresses&&listAddresses.size()>0)
{
Location = listAddresses.get(0).getAddressLine(0);
}
else
{
Toast.makeText(getBaseContext(), "Searching..",dur).show();
}
}
catch (Exception e)
{
//Toast.makeText(this,Location, dur).show();
Toast.makeText(getBaseContext(), "No address found",dur).show();
}
}
else
{
Toast.makeText(getApplicationContext(),"wait...",dur).show();
}
}
这个geo方法在得到经纬度后调用onLocationChanged方法,来获取位置。
【问题讨论】:
标签: android