Android (MapView): How to set the zoom level to 4 miles on the map?

I have latitude and longitude (GeoPoint), which is the center of the map. I want to set the zoom level at a distance of 4 miles from the latitude and longitude that I have.

Thanks Advance,

+6
source share
3 answers

You can use the setzoom () function to do this. The code below can be found in this example .

mc = mapView.getController(); String coordinates[] = {"1.352566007", "103.78921587"}; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); 
+3
source

SOLVED:

from the Androd google API: zoomlevel sets the scale of the map. The value will be sandwiched between 1 and 21 inclusive, although not all areas have tiles with a higher zoom level. It just sets the zoom level directly; Parameters: zoomLevel - When you zoom in 1, the Earth's equator is 256 pixels long. Each subsequent zoom level is increased by 2 times. Returns: a new zoom level from 1 to 21 inclusive.

So, taking into account the equator, E = 40,075 km or 21,638.8 miles, considering the distance to the zoom D = 20 km or miles

zoom level: L = log2 (E / D) +1

This is a simple method that I used do not forget to set E = 21.638.8 if you want to use miles ...

 public static byte zoomLevel (double distance){ byte zoom=1; double E = 40075; Log.i("Astrology", "result: "+ (Math.log(E/distance)/Math.log(2)+1)); zoom = (byte) Math.round(Math.log(E/distance)/Math.log(2)+1); // to avoid exeptions if (zoom>21) zoom=21; if (zoom<1) zoom =1; return zoom; } 
+14
source

Play with .setZoom(int); your card. I think its about 15:

so myMap.setZoom(15);

-1
source

Source: https://habr.com/ru/post/885503/


All Articles