android高德开发知识点
2017-11-05 本文已影响0人
Mr__小二
设置海量点
MultiPointOverlayOptions overlayOptions = new MultiPointOverlayOptions();
overlayOptions.icon(BitmapDescriptorFactory.fromBitmap(
BitmapFactory.decodeResource(getResources(),R.mipmap.goodcar)));//设置图标
overlayOptions.anchor(0.5f,0.5f); //设置锚点
multiPointOverlay = aMap.addMultiPointOverlay(overlayOptions);
Listlist = new ArrayList<>();
//创建MultiPointItem存放,海量点中某单个点的位置及其他信息
MultiPointItem multiPointItem = new MultiPointItem(latLng);
MultiPointItem multiPointItem2 = new MultiPointItem(latLng12);
MultiPointItem multiPointItem3 = new MultiPointItem(latLng13);
MultiPointItem multiPointItem4 = new MultiPointItem(latLng14);
list.add(multiPointItem);
list.add(multiPointItem2);
list.add(multiPointItem3);
list.add(multiPointItem4);
multiPointOverlay.setItems(list);//将规范化的点集交给海量点管理对象设置,待加载完毕即可看到海量点信息
// 定义海量点点击事件
AMap.OnMultiPointClickListener multiPointClickListener = new AMap.OnMultiPointClickListener() {
// 海量点中某一点被点击时回调的接口
// 返回 true 则表示接口已响应事件,否则返回false
@Override
public boolean onPointClick(MultiPointItem pointItem) {
Log.e("tag","海量点数据点击"+pointItem.getLatLng());
return false;
}
};
// 绑定海量点点击事件
aMap.setOnMultiPointClickListener(multiPointClickListener);
点平滑移动(轨迹)
// 获取轨迹坐标点
List<LatLng> points=new ArrayList<>();
points.add(latLng11);
points.add(latLng12);
points.add(latLng13);
points.add(latLng14);
points.add(latLng15);
LatLngBounds bounds = new LatLngBounds(points.get(0), points.get(points.size() - 2));
aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
SmoothMoveMarker smoothMarker = new SmoothMoveMarker(aMap);
// 设置滑动的图标
smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.mipmap.navi_map_gps_locked));
LatLng drivePoint = points.get(0);
Pair<Integer, LatLng> pair = SpatialRelationUtil.calShortestDistancePoint(points, drivePoint);
points.set(pair.first, drivePoint);
List<LatLng> subList = points.subList(pair.first, points.size());
// 设置滑动的轨迹左边点
smoothMarker.setPoints(subList);
// 设置滑动的总时间
smoothMarker.setTotalDuration(40);
// 开始滑动
smoothMarker.startSmoothMove();