Android 百度地图,手绘图形

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。