Failed to get the required scale in google map v2?

I’m working on an application in which the map zoom level, based on the movement of the search key, says the search step is 10 miles, and then calculate the exact scale scale of the map, which extends the distance of 10 miles on the map of the mobile screen. A more detailed description in the attached image enter image description here

my starting position for the search appliance is 1 mile and the maximum position is 50 miles when I move the maximum position in the search bar. Say, 50 maps cover only an area of ​​30 km, while it should be covered with an area of ​​80 km. I use code to achieve this -

private int zoomLevel(double _distance) { int newzoomlevel = 1; double distance = _distance * 1609.34; double equatorLength = 40075004; // in meters double widthInPixels = screenWidth(); double metersPerPixel = equatorLength / 256; int zoomLevel = 1; while ((metersPerPixel * widthInPixels) > distance) { metersPerPixel /= 2; ++zoomLevel; } Log.i("current zoom level", "zoom level = " + zoomLevel); if (zoomLevel <=19) { newzoomlevel = zoomLevel; } else { newzoomlevel = zoomLevel - 2; } return newzoomlevel; } 

I pass the seekpar position as a parameter since it is a mile in the method. I convert it to meter, multiplying 1609.34. but I can’t say that it’s not right, please help me in advance.

+4
source share

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


All Articles