美文网首页
Android 百度地图,手绘图形

Android 百度地图,手绘图形

作者: 不是作家ssssss | 来源:发表于2020-05-18 16:27 被阅读0次

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

BaiduMap.OnMapTouchListenerlistener =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

相关文章

网友评论

      本文标题:Android 百度地图,手绘图形

      本文链接:https://www.haomeiwen.com/subject/cntpohtx.html