百度地图相关

更换地图主题

将设置好的主题样式放入assets中

代码中(在setContentView(R.layout.activity_main)之前调用)

    private void initBaiduMap(){
        SDKInitializer.initialize(this);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try
                {
                    File mapStyleFile = new File(getFilesDir().getAbsolutePath() + "/custom_config_dark.txt");//主题样式的 
                    if(!mapStyleFile.exists()) {
                        InputStream is = getAssets().open("customConfigdir/custom_config_dark.txt");
                        FileOutputStream fos = new FileOutputStream(mapStyleFile);
                        byte[] buffer = new byte[1024];
                        int byteCount = 0;
                        while ((byteCount = is.read(buffer)) != -1) {//循环从输入流读取 buffer字节
                            fos.write(buffer, 0, byteCount);//将读取的输入流写入到输出流
                        }
                        fos.flush();//刷新缓冲区
                        is.close();
                        fos.close();
                    }
                    TextureMapView.setCustomMapStylePath(mapStyleFile.getAbsolutePath());
                    TextureMapView.setMapCustomEnable(true);
                } catch (Exception e){
                    e.printStackTrace();
                }
            }
        }).start();
    }

最后在需要出现这个地图主题的ativity中

  map.setMapCustomEnable(true); //设置个性化地图样式是否生效

去除logo

        View child = map.getChildAt(1);
        if (child != null && (child instanceof ImageView || child instanceof ZoomControls))
        {
            child.setVisibility(View.INVISIBLE);
        }


多个market的点击事件

循环设置market

  private void setMarket(latitude,longitude)
  {
       LatLng point = new LatLng(latitude, longitude);
        //定义Maker坐标点
//        //构建Marker图标
        BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.mipmap.ic_empoison_commonly);
        //构建MarkerOption,用于在地图上添加Marker
        OverlayOptions options = new MarkerOptions()
                .position(point)  //设置marker的位置
                .icon(bitmap)  //设置marker图标
//                .zIndex(2)  //设置marker所在层级
                .draggable(false);  //设置手势拖拽
        //在地图上添加Marker,并显示
        Overlay marker = mBaiduMap.addOverlay(options);
        Bundle bundle = new Bundle();
        bundle.putSerializable("point", point);
        marker.setExtraInfo(bundle);
    }

    private void setCircle(latitude,longitude)
    {
        LatLng point = new LatLng(latitude,longitude);
        int circleColor = 0;
        switch (dataMap.type)
        {
            case 1:
                circleColor = getResources().getColor(R.color.item_good);
                break;
            case 2:
                circleColor = getResources().getColor(R.color.item_opacitas);
                break;
            case 3:
                circleColor = getResources().getColor(R.color.item_alga);
                break;
            case 4:
                circleColor = getResources().getColor(R.color.item_element);
                break;
        }


        OverlayOptions ooCircle = new CircleOptions()
                .fillColor(circleColor)
                .center(point)
//                .stroke(new Stroke(5, circleColor))
                .radius(1400);
        mBaiduMap.addOverlay(ooCircle);
    }

onCreate中设置mBaiduMap的监听

  mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener()
        {
            @Override
            public boolean onMarkerClick(Marker marker)
            {
                DataMap dataMap = (DataMap) marker.getExtraInfo().get("point");
               
                return true;
            }
        });

百度地图在listview/recyclerview的滑动冲突
  mBaiduMap.setOnMapStatusChangeListener(new BaiduMap.OnMapStatusChangeListener()
        {
            LatLng startLng, finishLng;

            @Override
            public void onMapStatusChangeStart(MapStatus mapStatus)
            {
                startLng = mapStatus.target;
            }

            @Override
            public void onMapStatusChange(MapStatus mapStatus)
            {
            }

            @Override
            public void onMapStatusChangeFinish(MapStatus mapStatus)
            {
                // 滑动搜索
                finishLng = mapStatus.target;
                if (startLng.latitude != finishLng.latitude
                        || startLng.longitude != finishLng.longitude)
                {
                    Projection ject = mBaiduMap.getProjection();
                    Point startPoint = ject.toScreenLocation(startLng);
                    Point finishPoint = ject.toScreenLocation(finishLng);
                    double x = Math.abs(finishPoint.x - startPoint.x);
                    double y = Math.abs(finishPoint.y - startPoint.y);
                    if (x > 50 || y > 50)
                    {
                        //在这处理滑动
                        ll_detail.setVisibility(View.GONE);
                    }
                }
            }
        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值