How to implement Drop pin animation in android using google maps?

后端 未结 3 861
北荒
北荒 2021-02-04 22:13

I want to implement dropping pins animation to markers as the one in iPhone. The problem is pins are not dropping the way they should as they are in this link : http://googlege

3条回答
  •  清歌不尽
    2021-02-04 22:56

    I am posting the core concept that is working to have the drop pin animation in mapView as that of iPhopne. Same can be integrated with overlays also....

    Drawable drawableImage = this.getResources().getDrawable(R.drawable.marker);
    myCustomOverlay = new CustomOverlay(drawableImage, mapView);
    initGeoPoint = new GeoPoint((int) (latitudeArray[i] * 1E6),(int) (longitudeArray[i] * 1E6));
    OverlayItem overlayItem = new OverlayItem(initGeoPoint,getLocationAddress(latitudeArray[i], longitudeArray[i]),"xyz");
    
    myCustomOverlay.addOverlay(overlayItem);
    mapOverlays.add(myCustomOverlay);
    
    RelativeLayout v = (RelativeLayout) View.inflate(getApplicationContext(),R.layout.marker_layout, null);
    ImageView markerView = (ImageView) v.findViewById(R.id.marker_img_view);
    AnimationSet animation = new AnimationSet(true);
    
    TranslateAnimation translateAnimation = new TranslateAnimation(0.0f, 0.0f, -400.0f, 0.0f);
    translateAnimation.setDuration(1000);
    animation.addAnimation(translateAnimation);
    
    markerView.startAnimation(animation);
    
    mapView.addView(v, 
          new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT), 
          new GeoPoint((int) (latitude * 1E6),(int) (longitude * 1E6)),
          MapView.LayoutParams.BOTTOM_CENTER));
    
    mapView.invalidate();
    

    marker_layout is as folows:

    
    
    
        
    
    
    

    Overlay Class ###########

    public class CustomOverlay extends BalloonItemizedOverlay {
    
        private ArrayList m_overlays = new ArrayList();
        private Context c;
    
        public CustomOverlay(Drawable defaultMarker, MapView mapView) {
            super(boundCenter(defaultMarker), mapView);
            c = mapView.getContext();
        }
    
        public void addOverlay(OverlayItem overlay) {
            m_overlays.add(overlay);
            populate();
        }
    
        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
            if (!shadow) {
                super.draw(canvas, mapView, false);
            }
        }
    
        public void removeOverlay(OverlayItem overlay) {
            m_overlays.remove(overlay);
            populate();
        }
    
        @Override
        protected OverlayItem createItem(int i) {
            return m_overlays.get(i);
        }
    
        @Override
        public int size() {
            return m_overlays.size();
        }
    
        @Override
        protected boolean onBalloonTap(int index, OverlayItem item) {
            Toast.makeText(
                    c,
                    "onBalloonTap for overlay index " + index + " Item"
                            + item.getTitle(), Toast.LENGTH_LONG).show();
    
            String id = "";
    
            return true;
        }
    }
    

提交回复
热议问题