Android百度地图——覆盖物

在配置好百度地图的使用权限和key值之后,绘制地图覆盖物步骤:
1、初始化地图


    /**初始化百度地图
     * 
     */
    private void initBaiduMap(){
        //初始化地图
        mMapView = (MapView) findViewById(R.id.map);
        
        mMapView.showZoomControls(false);//缩放按钮
    
        mBaidumap = mMapView.getMap();
        //地图点击事件处理
        mBaidumap.setOnMapClickListener(this);
        // 初始化搜索模块,注册事件监听
        mSearch = RoutePlanSearch.newInstance();
        mSearch.setOnGetRoutePlanResultListener(this);
//        mBaidumap.setOnMapLoadedCallback(new OnMapLoadedCallback() {
//          //地图加载完成回调,该方法有时没有返回,原因不明,还在研究,读者有经验可以交流一下
//          @Override
//          public void onMapLoaded() {
//              // TODO Auto-generated method stub
//              ToastUtils.showTextToast(SelectStationActivity.this, "地图加载完成");
//              
//          }
//      });
    }

2、添加覆盖物

BitmapDescriptor bdC = BitmapDescriptorFactory.fromView(view);
/*
此处BitmapDescriptorFactory.fromView(view);采用的是自定义覆盖物
view = View.inflate(getApplicationContext(), R.layout.view_baidumap, null);
也可以使用BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)
BitmapDescriptorFactory.fromBitmap(bitmap)
*/
            LatLng ll = new LatLng(stations.get(i).getLatitude(), stations.get(i).getLongitude());
            MarkerOptions ooC = null;
            if (overlayIconCenter) {//true 居中对齐
                ooC = new MarkerOptions().position(ll)//经纬度
                                      .icon(bdC)//覆盖物的icon,可以选择icons(ArrayList<BitmapDescriptor>)多个icon实现轮播动画效果
                                      .perspective(false)
                                     .anchor(0.5f, 1f)//覆盖物的对齐点,0.5f,0.5f为覆盖物的中心点
                                     .zIndex(i);
            }else{//左对齐
                ooC = new MarkerOptions().position(ll).icon(bdC)
                    .perspective(false).anchor(0f, 1f).zIndex(i);
            }
                    
            if (animation) {   
                //生长动画
                ooC.animateType(MarkerAnimateType.grow);//还可以选择掉落的动画
            }
            mBaidumap.addOverlay(ooC);
                        /*此处可以强转(Marker) (mBaidumap.addOverlay(ooD));
                            通过Marker.setPosition(LatLng)控制覆盖物的位置
*/

3、覆盖物事件监听
mBaidumap.setOnMapStatusChangeListener(arg0);
mBaidumap.setOnMapDoubleClickListener(arg0);
mBaidumap.setOnMapTouchListener(arg0);
mBaidumap.setOnMapLongClickListener(arg0);
mBaidumap.setOnMarkerClickListener((arg0);

Baidumap.setOnMarkerClickListener(new OnMarkerClickListener() {
            
            @Override
            public boolean onMarkerClick(Marker arg0) {
                // TODO Auto-generated method stub
                //可以通过arg0.getZIndex()判断Marker
            
                return true;
            }
        });
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在第二篇文章的时候我曾经说过,还会有一篇添加覆盖物的讲解,这一篇就是专门写覆盖物的。百度地图SDK的覆盖物乍一看没...
    猫儿不吃鱼鱼阅读 5,292评论 3 9
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,219评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,908评论 18 139
  • 【 申请密钥AndroidSDK:应用程序包名+数字签名 As查看数字签名:cmd-----cd .android...
    征程_Journey阅读 2,337评论 0 5
  • 一个基督徒问牧师说:“上帝为什么不让亚当和夏娃吃智慧果呢?人拥有智慧,不是很好吗?”牧师说:“凡事都有两面性,智慧...
    海王星1984阅读 545评论 0 1