一.添加点击事件
MapViewTouchListener mMapViewTouchListener = new MapViewTouchListener(this, mMapView);
mMapView.setOnTouchListener(mMapViewTouchListener);
二 定义MapViewTouchListener类,即地图界面单击事件类
class MapViewTouchListener extends DefaultMapViewOnTouchListener {
//这里放第1步的构造函数
}
1.初始化构造函数,主要是指定点击事件对应哪个地图界面
public MapViewTouchListener(Context context, MapView mapView) {
super(context, mapView);
//调用的就是父类efaultMapViewOnTouchListener中的空参数的构造函数,this.mMapView = mapView;初始化一些从外部传入的参数
}
2.重写单击事件
public boolean onSingleTapConfirmed(MotionEvent e) {
//1)
}
1)获取用户在屏幕上点击的点
android.graphics.Point screenPoint = new android.graphics.Point((int) e.getX(), (int) e.getY());
2)定义一个多线程的对象,ListenableFuture帮我们检测Future是否完成了,如果完成就自动调用回调函数,这样可以减少并发程序的复杂度。
final ListenableFuture<List> overlaysAsync = mMapView.identifyGraphicsOverlaysAsync(screenPoint, 10.0, false, 2);
3)给多线程对象加入一个监听的线程
try {
List overlayResultList = overlaysAsync.get();