Android 百度地图,手绘图形

首先,根据百度地图的BaiduMap.OnMapTouchListener的方法,获取当前点击屏幕的坐标位置

 BaiduMap.OnMapTouchListener listener = new BaiduMap.OnMapTouchListener() {

        /**
         * 当用户触摸地图时回调函数
         *
         * @param motionEvent 触摸事件
         */
        @Override
        public void onTouch(MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_MOVE:
                    if (isDrawRectangle) {
                        latLngList.clear();
                        if (markerOverlayRe != null) {
                            markerOverlayRe.remove();
                        }
                        isDrawRectangle = false;
                    }
                    Point point = new Point((int) (motionEvent.getX()), (int) (motionEvent.getY()));
                    LatLng latlng = mBaiduMap.getProjection().fromScreenLocation(point);
                    latLngList.add(latlng);
                    initRectangle();
                    break;
                case MotionEvent.ACTION_UP:
                    isDrawRectangle = true;
                    break;
            }
        }
    };

其中,主要是

Point point =new Point((int) (motionEvent.getX()), (int) (motionEvent.getY()));

LatLng latlng =mBaiduMap.getProjection().fromScreenLocation(point);

这两句话,用于屏幕坐标点转为百度地图的经纬度。

然后收集移动点的集合,取第一个值和最后一个值,就可以绘制矩形了。其他图形原理相同,有不明白的小伙伴可以加我qq:729134709

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值