android高德地图根据经纬度添加标注(Marker)
onCreate方法中添加 :
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mapView.onCreate(savedInstanceState);//mapView为高德地图 MapView //AMap是地图对象 aMap = mapView.getMap();//得到AMap对象 latitude 维度 longitude 精度 经纬度设置成自己的经纬度即可 CameraPosition cameraPosition = new CameraPosition(new LatLng(this.latitude, this.longitude), 15, 0, 30); CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition); aMap.moveCamera(cameraUpdate);
//添加标注 addMarkers(); }
添加标注(marker)
/** * 添加标注 */ private void addMarkers() { MarkerOptions markerOptions = new MarkerOptions(); markerOptions.anchor(1.3f, 1.5f);//点标记的锚点 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_map_add); markerOptions.icon(BitmapDescriptorFactory .fromBitmap(bitmap)); markerOptions.position(new LatLng(latitude, longitude)); Marker growMarker = aMap.addMarker(markerOptions); growMarker.setClickable(true); //marker 设置是否可点击 startGrowAnimation(growMarker); growMarker.showInfoWindow(); }
添加标注的生长动画效果:
private void startGrowAnimation(Marker marker) { if (marker != null) { Animation animation = new ScaleAnimation(0, 1, 0, 1); animation.setInterpolator(new LinearInterpolator()); //整个移动所需要的时间 animation.setDuration(1000); animation.setFillMode(1);//动画保存之前的状态为1 之后为0 //设置动画 marker.setAnimation(animation); //开始动画 marker.startAnimation(); marker.showInfoWindow(); } }
最后onDestyoy销毁:
@Override protected void onDestroy() { super.onDestroy(); mapView.onDestroy(); }