Animate markers on Google MapView

放肆的年华 提交于 2019-12-06 10:51:20

You can use this tutorial for a reference, it uses animations, so I think that suits your solution.

Code from the tutorial :

//Reference to our MapView
MapView mapView = (MapView) activity.findViewById(R.id.mapview);

//Get a LayoutInflater and load up the view we want to display.
//The false in inflater.inflate prevents the bubble View being added to the MapView straight away
LayoutInflater inflater = activity.getLayoutInflater();
LinearLayout bubble = (LinearLayout) inflater.inflate(R.layout.bubble, mapView, false);

//Set up the bubble's close button
ImageButton bubbleClose = (ImageButton) bubble.findViewById(R.id.bubbleclose);
bubbleClose.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Animation fadeOut = AnimationUtils.loadAnimation(ResultsMapResultsDisplayer.this.activity, R.anim.fadeout);
        bubble.startAnimation(fadeOut);
        bubble.setVisibility(View.GONE);
    }
});

private void displaySearchResultBubble(final SearchResult result) {
    //Hide the bubble if it's already showing for another result
    map.removeView(bubble);
    bubble.setVisibility(View.GONE);

    //Set some view content
    TextView venueName = (TextView) bubble.findViewById(R.id.venuename);
    venueName.setText(result.getName());

    //This is the important bit - set up a LayoutParams object for positioning of the bubble.
    //This will keep the bubble floating over the GeoPoint result.getPoint() as you move the MapView around,
    //but you can also keep the view in the same place on the map using a different LayoutParams constructor
    MapView.LayoutParams params = new MapView.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
        result.getPoint(), MapView.LayoutParams.BOTTOM_CENTER);

    bubble.setLayoutParams(params);

    map.addView(bubble);
    //Measure the bubble so it can be placed on the map
    map.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

    //Runnable to fade the bubble in when we've finished animatingTo our OverlayItem (below)
    Runnable r = new Runnable() {
        public void run() {
            Animation fadeIn = AnimationUtils.loadAnimation(activity, R.anim.fadein);
            bubble.setVisibility(View.VISIBLE);
            bubble.startAnimation(fadeIn);
        }
    };

    //This projection and offset finds us a new GeoPoint slightly below the actual OverlayItem,
    //which means the bubble will end up being centered nicely when we tap on an Item.
    Projection projection = map.getProjection();
    Point p = new Point();

    projection.toPixels(result.getPoint(), p);
    p.offset(0, -(bubble.getMeasuredHeight() / 2));
    GeoPoint target = projection.fromPixels(p.x, p.y);

    //Move the MapView to our point, and then call the Runnable that fades in the bubble.
    mapController.animateTo(target, r);
 }

I seen your example app. From that i think you need only Glow in your markers, right? If yes then its possible through the styles and its having glow property also.

So I got it to work using a simple ArrayList of ImageViews and animation on them, no MapOverlay.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!