I want to achieve marker animations, such as GIF animations. I got two images that should blink at the same time. I did not find anything that can be achieved in android. I am trying to do this by creating a handler that runs every 1 second, and I am trying to set the icon for the marker. But that does not work. Please guide me in the right direction.
my code currently looks like this.
Handler handler = new Handler(); Boolean marker_color_bool = true; //adding marker and sending the marker instance to marker_animation() method where handler is called. MarkerOptions marker = new MarkerOptions() .title(delivery_center_name) .snippet("This is the " + delivery_center_name + " location") .position(location) .icon(BitmapDescriptorFactory.fromResource(R.drawable.red_marker)); google_map.addMarker(marker); marker_animation(marker);
marker_animation () method
private final int ONE_SECONDS = 1000; public void marker_animation(final MarkerOptions marker ) { handler.postDelayed(new Runnable() { public void run() { Log.e("running",""+marker_color_bool); if(marker_color_bool == true) { marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.green_marker)); marker_color_bool = false; } else { marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.red_marker)); marker_color_bool = true; } handler.postDelayed(this, ONE_SECONDS); } }, ONE_SECONDS); }
this approach does not work. Please help me what I am doing wrong.
android google-maps google-maps-android-api-2 android-handler google-maps-markers
Sandeep r
source share