stanley
stanley

Reputation: 529

How to animate a marker(Overlay) image in mapview

I'm developing an android application which uses google maps. I want to display an overlay image with some coordinates in the MapView. I need to animate the image. Please help. My code is as follows

    mapView = (MapView) findViewById(R.id.myGMap);
    mapView.setBuiltInZoomControls(true);
    mapController = mapView.getController();
    mapView.buildDrawingCache();
    mapView.setAnimationCacheEnabled(true);
    mapView.setClickable(true);
    mapView.getZoomLevel();
    mapView.displayZoomControls(true);
    mapView.getMapCenter(); 

    List<Overlay> mapOverlays = mapView.getOverlays();

    drawable = getResources().getDrawable(R.drawable.img1);
    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);

    int latitudeE6 = (int)((12.907382) * 1000000);
    int longitudeE6 = (int)((77.595105) * 1000000);
    point = new GeoPoint(latitudeE6,longitudeE6);       
    overlayitem = new OverlayItem(point, "", "");
    mapController.animateTo(point);     
    itemizedoverlay.addOverlay(overlayitem);
    itemizedoverlay.getCenter();
    itemizedoverlay.getFocus();

    mapOverlays.add(itemizedoverlay);

Upvotes: 2

Views: 2345

Answers (2)

Juliousraj
Juliousraj

Reputation: 61

public static void addAnimationToMap(MapView map, int animationResourceId, GeoPoint geoPoint)

{   
 final ImageView view = new ImageView(map.getContext());

    view.setImageResource(animationResourceId);

    //Post to start animation because it doesn't start if start() method is called in activity OnCreate method.
    view.post(new Runnable() {
        @Override
        public void run() {
            AnimationDrawable animationDrawable = (AnimationDrawable) view.getDrawable();
            animationDrawable.start();
        }
    });

    map.addView(view);

    MapView.LayoutParams layoutParams = new MapView.LayoutParams(
        MapView.LayoutParams.WRAP_CONTENT,
        MapView.LayoutParams.WRAP_CONTENT,
        geoPoint,
        MapView.LayoutParams.BOTTOM_CENTER);
    view.setLayoutParams(layoutParams);
}

You can add animation list in res->drawable and pass the drawable to this function. AFAIK the only possible way to add animated marker on google map is to add a view above the map

Upvotes: 3

Hesham Saeed
Hesham Saeed

Reputation: 5378

I believe this is hard thing to do, but you can use the alpha feature from the drawable to create alpha animation as follows:

drawable.setAlpha();

Upvotes: 0

Related Questions