public class MyLocationListener implements BDLocationListener {
@Override
public void onReceiveLocation(final BDLocation location) {
runOnUiThread(new Runnable() {
@Override
public void run() {
StringBuffer currentPosition = new StringBuffer();
currentPosition.append("纬度:").append(location.getLatitude()).append("\n");
currentPosition.append("经线:").append(location.getLongitude()).append("\n");
currentPosition.append("国家:").append(location.getCountry()).append("\n");
currentPosition.append("省:").append(location.getProvince()).append("\n");
currentPosition.append("市:").append(location.getCity()).append("\n");
currentPosition.append("区:").append(location.getDirection()).append("\n");
currentPosition.append("街道:").append(location.getStreet()).append("\n");
currentPosition.append("定位方式:");
if (location.getLocType() == BDLocation.TypeGpsLocation) {
currentPosition.append("GPS");
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
currentPosition.append("网络");
}
positionText.setText(currentPosition);
}
});
}
}
为什么我的onReceiveLocation(final BDLocation location)中的location要设置为final?不然后面的location.getLatitude()方法不能用
嗯 怎么说呢 在匿名对象的方法里去调用方法里的形参的话,为了防止形参在被调用时被篡改而强行加的。 你这里的方法是在runOnUiThread的一个匿名线程对象里调用的。把逻辑放到外面就不用了加final了
用final修饰的参数不允许修改
http://blog.csdn.net/tavor/article/details/1920336