Android 百度地图,手绘图形

2020-05-18  本文已影响0人  不是作家ssssss

首先,根据百度地图的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

上一篇 下一篇

猜你喜欢

热点阅读