Lucas Lisbon Lucas Lisbon - 3 months ago 25
Android Question

How to zoom to specific marker — osmdroid API (version 5.2@aar)

Marker example:

Marker m = new Marker(mapOSM);
//m.setTitle("LOL");
m.setSnippet("bla bla bla);
m.setPosition(new GeoPoint(cenario.getLatitude(), cenario.getLongitude()));

Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_action_place, null);
icon.setColorFilter(getResources().getColor(R.color.md_green_400), PorterDuff.Mode.MULTIPLY);

m.setIcon(icon);

mapOSM.getOverlays().add(m);


I know how to animate to a position:

mapOSM.getController().animateTo(m.getPosition());


But how to zoom to a specific marker??

Answer

Ugly solution:

Do it

mapOSM.getController().setZoom(10);

And then do it

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            mapOSM.getController().animateTo(new GeoPoint(x, y));
        }
    }, 300);