android 实现计算百度地图两点之间旋转角度,多点有向连接
2018-03-28 16:23
726 查看
地图文档:http://wiki.lbsyun.baidu.com/cms/androidsdk/doc/v3_4_0/
private int MUL = 100_0000;
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.ic_start_location);
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<>();
相关文章推荐
- 百度地图实现计算两点之间的距离
- 同一坐标系中,由任意两点计算地图旋转角度
- JavaScript 实现的根据经纬度计算地球上两点之间的距离
- 百度地图如何计算两点之间距离
- Android Touch事件 两点旋转实现思路
- ios 利用自带的CoreLocation.framework 实现获取手机当前处于的精度和纬度 并计算两点之间的间距(特别使用于团购,附近商户之类的项目)
- Android开发_拖动效果,旋转效果,两点放大缩小的实现
- 利用JS实现的根据经纬度计算地球上两点之间的距离
- 计算两点之间的距离,两点之间的斜率(角度)--秀清
- 百度地图之调用URL api接口实现周边搜索及计算球面两点间的距离
- 利用JS实现的根据经纬度计算地球上两点之间的距离
- 利用JavaScript实现的根据经纬度计算地球上两点之间的距离
- 利用JS实现的根据经纬度计算地球上两点之间的距离
- 百度地图开发:如何计算两点之间距离
- 百度地图如何计算两点之间距离
- android根据经纬度计算两点之间的距离
- 百度地图如何计算两点之间距离
- 百度地图如何计算两点之间距离
- android百度地图:地图缩放、旋转、俯视角度以及屏幕像素与经纬度的转换Projection
- 百度地图如何计算两点之间距离