android+百度地图围栏,地理围栏

private void drawFence(GeoFence fence) {

switch (fence.getType()) {

case GeoFence.TYPE_ROUND:

drawCircle(fence, false);

break;

case GeoFence.TYPE_BDMAPPOI:

drawCircle(fence, true);

break;

case GeoFence.TYPE_POLYGON:

drawPolygon(fence);

break;

default:

break;

}

// 设置所有maker显示在当前可视区域地图中

LatLngBounds bounds = boundsBuilder.build();

MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLngBounds(bounds, 50,

50, 50, 50);

// 更新地图状态

mBdMap.animateMapStatus(mapStatusUpdate);

removeMarkers();

}

/**

* 绘制圆

*/

private void drawCircle(GeoFence fence, boolean isPoi) {

LatLng center;

int radius;

if (isPoi) {

BDLocation bdLocation = new BDLocation();

bdLocation.setLatitude(fence.getCenter().getLatitude());

bdLocation.setLongitude(fence.getCenter().getLongitude());

BDLocation tempLocation = LocationClient

.getBDLocationInCoorType(bdLocation, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);

center = new LatLng(tempLocation.getLatitude(),

tempLocation.getLongitude());

} else {

center = centerLatLng;

}

radius = (int) fence.getRadius();

// 绘制一个圆形

if (center == null) {

return;

}

mBdMap.addOverlay(new CircleOptions().center(center)

.radius(radius)

.fillColor(0x666495ED) // 填充颜色

.stroke(new Stroke(3, 0xE66495ED)));

boundsBuilder.include(center);

if (!isPoi) {

centerLatLng = null;

}

}

/**

* 绘制Polygon

*/

private void drawPolygon(GeoFence fence) {

final List pointList = fence.getPoints();

if (null == pointList || pointList.isEmpty()) {

return;

}

List lst = new ArrayList<>();

for (DPoint point : pointList) {

lst.add(new LatLng(point.getLatitude(), point.getLongitude()));

boundsBuilder.include(

new LatLng(point.getLatitude(), point.getLongitude()));

}

mBdMap.addOverlay(new PolygonOptions()

.points(polygonPoints)

.fillColor(0x666495ED) // 填充颜色

.stroke(new Stroke(5, 0xE66495ED)));

if (polygonPoints != null && polygonPoints.size() > 0) {

polygonPoints.clear();

}

}

复制

深色

复制成功

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值