android 百度地图 自定义地图标注,android 百度地图自定义圆,更改默认图标等常用方法...

总结了一下百度地图常用的方法(前提是集成百度地图环境成功):

1:定位到已经经纬度,只需要改变latlng的参数即可。有两种方法:

方法1:

//定义maker坐标点

latlng point = new latlng(39.963175, 116.400244);

//构建marker图标

bitmapdescriptor bitmap = bitmapdescriptorfactory

.fromresource(r.mipmap.ic_launcher);

//构建markeroption,用于在地图上添加marker

overlayoptions option = new markeroptions()

.position(point)

.icon(bitmap);

//在地图上添加marker,并显示

baidumap.getmap().addoverlay(option);

方法2:

mylocationdata locdata = new mylocationdata.builder()

// 此处设置开发者获取到的方向信息,顺时针0-360

.direction(100).latitude(result.getlocation().latitude)

.longitude(result.getlocation().longitude).build();

// 设置定位数据

baidumap.setmylocationdata(locdata);

2:根据关键词key检索附近建筑(默认返回10条数据)

//经纬度搜索

poisearch.searchnearby(new poinearbysearchoption().keyword("生").radius(5000).location(new latlng(39.963175, 116.400244)));

//城市搜索

poisearch.searchincity(new poicitysearchoption().city("杭州").keyword("东方通信科技园").pagecapacity(1));

poisearch.setongetpoisearchresultlistener(this);

@override

public void ongetpoiresult(poiresult poiresult) {

if (poiresult == null || poiresult.error == searchresult.errorno.result_not_found) {

return;

}

if (poiresult.error == searchresult.errorno.no_error) {

//附近搜索

baidumap.getmap().clear();

//创建poioverlay

poioverlay overlay = new mypoioverlay(baidumap.getmap());

//设置overlay可以处理标注点击事件

baidumap.getmap().setonmarkerclicklistener(overlay);

//设置poioverlay数据

overlay.setdata(poiresult);

//添加poioverlay到地图中

overlay.addtomap();

overlay.zoomtospan();

return;

}

}

3:地图放大设置zoom:

/**

* 设置地图放大的倍数

*/

mbaidumap.setmapstatus(mapstatusupdatefactory.newmapstatus(new mapstatus.builder().zoom(18).build()));

4:

更改默认图标有两种方法:

方法1

/**

* 更改定位默认图标mylocationconfiguration 第二个参数是是否显示方向信息

*/

mylocationconfiguration.locationmode mcurrentmode = mylocationconfiguration.locationmode.normal;

bitmapdescriptor mcurrentmarker = bitmapdescriptorfactory

.fromresource(r.drawable.icon_map_gcoding);

mbaidumap.setmylocationconfiguration(new mylocationconfiguration(mcurrentmode, false, mcurrentmarker));

方法2:

//定义maker坐标点

//构建marker图标

bitmapdescriptor bitmap = bitmapdescriptorfactory

.fromresource(r.drawable.icon_map_gcoding);

//构建markeroption,用于在地图上添加marker

overlayoptions options = new markeroptions()

.position(ll)

.icon(bitmap);

//在地图上添加marker,并显示

mbaidumap.addoverlay(options);

5:将定位到的地方移到地图中央

/**

* 将定位到的地方移到地图中央

*/

latlng ll = new latlng(location.getlatitude(), location.getlongitude());

mapstatusupdate msu = mapstatusupdatefactory.newlatlng(ll);

mbaidumap.animatemapstatus(msu);

6:在地图中央的地方画圆:

// 添加圆

overlayoptions oocircle = new circleoptions().fillcolor(0x2201a4f1)

.center(ll).stroke(new stroke(5, 0xaa01a4f1))

.radius(200);

mbaidumap.addoverlay(oocircle);

7:当地图放大时,不让默认的圆出现(不设置accuracy即可),

// 构造定位数据 accuracy设置精确度

mylocationdata locdata = new mylocationdata.builder()

// 此处设置开发者获取到的方向信息,顺时针0-360

.direction(100).latitude(location.getlatitude())

.longitude(location.getlongitude()).build();

// 设置定位数据

mbaidumap.setmylocationdata(locdata);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值