简体   繁体   中英

Animate map to marker position in onClick method

I found a strange bug in the googleMap v2. When I try to animateCamrea to a marker position inside of the override Marker onClick method it doesn't work. Only moveCamera seems to work in this scenario. Even when I try to animate camera to a random position it still doesn't work.

@Override
public boolean onMarkerClick(Marker mmarker) {

    if(mmarker.getSnippet().equals("CITY")){

        map.animateCamera(CameraUpdateFactory.newLatLngZoom(mmarker.getPosition(), (float) 11.20));
        //updateMapMarkers(0);
    }

    return false;
}

This is the default behaviour. Why are you re-defining it?

If you return false from onMarkerClick , the Maps API will perform its default behaviour (panning to the marker).

You'll want to return true if you are overriding that behaviour or don't want it to happen.

Check the documentation for OnMarkerClickListener for more information.

If you only want to animate on a condition like that, then this will be more succinct:

@Override
public boolean onMarkerClick(Marker mmarker) {
    return !mmarker.getSnippet().equals("CITY");
}

This will pan the map only when the snippet is "CITY". You may also want to reverse the call to equals() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM