android 百度地图不能点击marker

 先看代码

声明监听器

mrakerListener=new BaiduMap.OnMarkerClickListener() {
            //marker被点击时回调的方法
            //若响应点击事件,返回true,否则返回false
            //默认返回false
            @Override
            public boolean onMarkerClick(Marker marker) {
                View view = View.inflate(getApplicationContext(), R.layout.map_info, null);
                TextView sj = view.findViewById(R.id.sj);
                TextView ms = view.findViewById(R.id.ms);
                TextView wz = view.findViewById(R.id.wz);
                TextView wc = view.findViewById(R.id.wc);
                final InfoWindow mInfoWindow = new InfoWindow(view, marker.getPosition(), -47);

                Bundle bundle = marker.getExtraInfo();

                sj.setText("时间:"+bundle.getString("sj"));
                wz.setText("位置:"+bundle.getString("wz"));
                ms.setText("定位模式:"+bundle.getString("ms"));
                wc.setText("误差:"+bundle.getString("wc")+"米");

                mBaidumap.showInfoWindow(mInfoWindow);
                return false;
            }
        };
        mBaidumap.setOnMarkerClickListener(mrakerListener);

画marker和折线,问题出在开始的时候先画marker,再画折线,但是折线太多了,把marker挡住了,导致marker无法点击,把绘制顺序颠倒一下就行了 

OverlayOptions mOverlayOptions = new PolylineOptions()
		.width(10)
		.color(WzckActivity.this.getResources().getColor(R.color.ploylineColor))
		.points(gjlist);
//在地图上绘制折线
//mPloyline 折线对象
Overlay mPolyline = mBaidumap.addOverlay(mOverlayOptions);

LatLng endpoint = gjlist.get(0);
MapStatus mMapStatus = new MapStatus.Builder()//定义地图状态
		.target(endpoint)
		.zoom(18)
		.build();  //定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
mBaidumap.setMapStatus(mMapStatusUpdate);//改变地图状态

//定义Maker坐标点
LatLng point = gjlist.get(jsonArray.length()-1);
//构建Marker图标
BitmapDescriptor bitmap = BitmapDescriptorFactory
		.fromResource(R.mipmap.ic_map_end);
//构建MarkerOption,用于在地图上添加Marker
OverlayOptions option = new MarkerOptions()
		.position(point)
		.icon(bitmap);
//在地图上添加Marker,并显示
Marker marker=(Marker)mBaidumap.addOverlay(option);
Bundle bundle=new Bundle();
bundle.putString("ms", startPositionMode);   //携带对象数据
bundle.putString("wz", point.longitude+","+point.latitude);   //携带对象数据
bundle.putString("sj", startTime);   //携带对象数据
bundle.putString("wc", "500");   //携带对象数据

marker.setExtraInfo(bundle);

 

 

上一篇:上传Appstore报错ERROR ITMS-90171


下一篇:adt-bundle环境搭建(Win7+Win10)