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()方法不能用