重拾丢却的梦 2017-12-03 04:52 采纳率: 100%
浏览 1679
已结题

百度地图onReceiveLocation()中location要设置为final

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

  • 写回答

2条回答 默认 最新

  • 正在吃饭的晓雨 2018-07-18 02:24
    关注

    嗯 怎么说呢 在匿名对象的方法里去调用方法里的形参的话,为了防止形参在被调用时被篡改而强行加的。 你这里的方法是在runOnUiThread的一个匿名线程对象里调用的。把逻辑放到外面就不用了加final了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器