android 实现计算百度地图两点之间旋转角度,多点有向连接

地图文档:http://wiki.lbsyun.baidu.com/cms/androidsdk/doc/v3_4_0/

private int MUL = 100_0000;
private List<Overlay> overlayList = new ArrayList<>();
private LatLng latlngLarger(LatLng latLng) {
    return new LatLng(latLng.latitude * MUL, latLng.longitude * MUL);
}

private Float rotation(LatLng bigStart, LatLng bigEnd) {
    bigStart = latlngLarger(bigStart);
    bigEnd = latlngLarger(bigEnd);
    if (bigEnd.longitude != bigStart.longitude) {
        double tan = (bigEnd.latitude - bigStart.latitude) / (bigEnd.longitude - bigStart.longitude);
        double atan = Math.atan(tan);
        double deg = atan * 360 / (2 * Math.PI);
        if (bigEnd.longitude < bigStart.longitude) {
            deg = -deg + 90 + 90;
        } else {
            deg = -deg;
        }
        return (float) -deg;
    } else {
        double disy = bigEnd.latitude - bigStart.latitude;
        int bias = 1;
        if (disy > 0) {
            bias = -1;
        }
        return -bias * 90f;
    }
}

调用方式:

BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.ic_start_location);
float rtateF = rotation(desLatLng, desLatLngNext);
OverlayOptions option = new MarkerOptions().position(desLatLng).icon(bitmap).anchor(0.5f, 0.5f).rotate(rtateF);

//在地图上添加Marker,并显示
Overlay overlay = mBaiduMap.addOverlay(option);
Bundle bundle = new Bundle();
bundle.putInt("index", i);
overlay.setExtraInfo(bundle);
overlayList.add(overlay);

附带地图弹窗及点击事件:
Button button = new Button(this);
button.setText(carLocationInfo.getCarPosition().get(marker.getExtraInfo().getInt("index")).getGtm());
button.setBackgroundResource(R.drawable.shape_rect_cor_blue_white);
//定义用于显示该InfoWindow的坐标点
LatLng pt = marker.getPosition();
//创建InfoWindow , 传入 view, 地理坐标, y 轴偏移量
InfoWindow mInfoWindow = new InfoWindow(button, pt, -47);
//显示InfoWindow
mBaiduMap.showInfoWindow(mInfoWindow);
button.setOnClickListener(view -> {
    mBaiduMap.hideInfoWindow();
});



private List<Overlay> overlayList = new ArrayList<>();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值