android百度地图覆盖物再下边,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)多个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;

}

});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值