Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-size zoom on Google Maps in java? (depending android screen resolution)

I've got 2 GeoPoints given to show them on the map with markers.

How can I get the optimum zoom level for the MapController in order to focus the middle of both points, but also have them on the map.

The whole thing should work at different screen resolutions.

like image 544
poeschlorn Avatar asked Apr 19 '10 11:04

poeschlorn


People also ask

How do I change the default zoom on Google Maps?

You can change the zoom level of the map using simple steps. Step 1 Go to Add or Edit Map page . Step 2 Select 'Default zoom level' in the 'Map Information section'. Step 3 click save map and see the changes.

How do I zoom in Google Maps API?

Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map for touchscreen devices.

How do I fix zoom on Google Maps?

To fix Google maps zooming problems, for Google maps default zoom you want to know how to change the zoom level on Google Maps. You can change the zoom level by going to the Edit map page and then selecting 'default zoom level' in the map information section and then clicking save map.


1 Answers

You can do this using the MapView's MapController. You get the MapController using MapView.getController(), then you can attempt to set the correct zoom using MapController.zoomToSpan(). I also tend to use ItemizedOverlay's getLatSpanE6() and getLonSpanE6() to make this simpler. An example:

MapView map = (MapView) findViewById(R.id.Map);
MapController mc = map.getController();
mc.zoomToSpan(overlay.getLatSpanE6(), overlay.getLonSpanE6());

It is important to note their caveat:

Because the zoom can only achieve discrete levels, and because the aspect ratio of the map may not match the ratio given, the quality of the fit may vary. The only thing we guarantee is that, after the zoom, at least one of the new latitude or the new longitude will be within a factor of 2 from the corresponding parameter.

Edit: In order to also get the map to zoom on the correct place, you have to use MapController.setCenter().

like image 120
Dan Lew Avatar answered Sep 19 '22 18:09

Dan Lew