Q:

Show location every 10 seconds in Android Studio

I'm doing an app in which every 10 seconds the location appears in a different place on the map, the bad thing is that it does not work for me and when I run the program I see all the locations already in place. but I want that every 10 seconds go by placing one by one as if they were moving.
This is my code:
    @Override
    public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    for ( contador=1;contador<=10;contador++) {

            final long EXECUTION_TIME = 10000;
            handler.postDelayed(new Runnable() {

            @Override
            public void run() {

               handler.postDelayed(this, EXECUTION_TIME);
            }
        }, EXECUTION_TIME);

        mMap.addMarker(new MarkerOptions().position(obtenerLatLong(contador)).title("Mi Hogar").snippet("Municipio").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(obtenerLatLong(contador), 17));

    }
}

any way to do it?

A:

Your handlers do nothing but launching other handlers, you have to make the addMarker and moveCamera calls inside the run() and at the end of the run() launch the next postDelayed. You can use a int to count and see where you are in the loop and launch another handler only if this int is under 10. (here i used cpt to do that)
final long EXECUTION_TIME = 10000;
final Handler handler = new Handler();

handler.postDelayed(new Runnable() {
    int cpt = 1;
    @Override
    public void run() {
        /* old
        * mMap.addMarker(new MarkerOptions().position(obtenerLatLong(contador)).title("Mi Hogar").snippet("Municipio").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
        * mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(obtenerLatLong(contador), 17));
        */
        //new
        mMap.addMarker(new MarkerOptions().position(obtenerLatLong(cpt)).title("Mi Hogar").snippet("Municipio").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(obtenerLatLong(cpt), 17));

        cpt++;
        if(cpt <= 10)
            handler.postDelayed(this, EXECUTION_TIME);
    }
}, EXECUTION_TIME);

