Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android map v2 marker onclick doesn't zoom

I use a latlngbound to show mutli markers on the map v2. And when I click either one of the markers, I want the camera to zoom in.

        private void loadCenter(){

        Builder boundsBuilder  = new LatLngBounds.Builder();
        for (int i=0;i<mmarker.saveMarker.size();i++)
        {
            boundsBuilder.include(mmarker.saveMarker.get(i));
        }
        LatLngBounds bounds = boundsBuilder.build();

          map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 60));
}

    @Override
    public boolean onMarkerClick(Marker mMarker) {
        // TODO Auto-generated method stub
        Toast.makeText(this, "MARKER CLICKED", Toast.LENGTH_LONG).show();
                CameraUpdate zoom=CameraUpdateFactory.newLatLngZoom(mMarker.getPosition(), 15);

                map.animateCamera(zoom);
        return false;
    }

I use the on marker click listener to detect the click on the marker. The toast in the method works. But the camera just won't zoom in, do you know why? thank you!

like image 671
Tony Tong Avatar asked Sep 27 '13 15:09

Tony Tong


1 Answers

try:

            new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                getMap().animateCamera(CameraUpdateFactory.newLatLngZoom(mk.getPosition(), level));
            }
        }, 300);

I was implementing something similar and came across the same problem and noticed that the api has some problems with timming the request. this worked for me.

like image 90
Pmsc Avatar answered Nov 15 '22 11:11

Pmsc