下面代码中的 toast 消息似乎没有显示,我无法确定原因。我错过了一个错误吗?
MyCurrentLocation
是活动名称
public class MyLocationListener implements LocationListener{
Geocoder gc = new Geocoder(MyCurrentLocation.this.getApplicationContext(), Locale.getDefault());
public void onLocationChanged(Location loc){
try{
loc.getLatitude();
loc.getLongitude();
List <Address> addr = gc.getFromLocation(loc.getLatitude(),loc.getLongitude(),1);
String results = "";
if (addr.size() > 0){
results += addr.get(0).getCountryName();
}
Toast.makeText(getApplicationContext(),results,Toast.LENGTH_LONG).show();
} catch(Exception e){
}