Skip to content Skip to sidebar Skip to footer

Googlemap.animatecamera Not Working On Background Thread

How do I change the camera focus inside a background thread? The zoom works fine in the thread, but changing the coordinates doesn't. Also changing the coordinates works if not use

Solution 1:

Probably because you may not be running this in a main UI thread

Change

map.animateCamera(CameraUpdateFactory.newLatLng(points.get(0)));
map.animateCamera(CameraUpdateFactory.zoomTo(14));

to

runOnUiThread(new Runnable() {

                     @Override
                     publicvoidrun() {
                            map.animateCamera(CameraUpdateFactory.newLatLng(points.get(0)));
                            map.animateCamera(CameraUpdateFactory.zoomTo(14));
                     }
                    });

Solution 2:

AnimateCamera API is implemented in another thread already for you. So you must call it in UI thread. Details about API

Post a Comment for "Googlemap.animatecamera Not Working On Background Thread"