0

I need to calculate a square area that is equivalent to different zoom heights. To achieve this I am using the scale in meters as radius and the latitude and longitude of where I click (LatLng center).

Doing it this way I get a square area, but it's too imprecise as you zoom out. `

public static LatLngBounds getBboxFromCenterWithRadius(double radius, LatLng center){
    double earthRadius = 6371000;
    double longMin = center.longitude -
            Math.toDegrees(radius/earthRadius/Math.cos(Math.toRadians(center.latitude)));
    double longMax= center.longitude +
            Math.toDegrees(radius/earthRadius/Math.cos(Math.toRadians(center.latitude)));
    double latMax = center.latitude + Math.toDegrees(radius/earthRadius);
    double latMin = center.latitude - Math.toDegrees(radius/earthRadius);
    LatLng sw = new LatLng(latMin,longMin);
    LatLng ne = new LatLng(latMax,longMax);
    return new LatLngBounds(sw, ne);
}

`

LDHugeman
  • 1
  • 1
  • Can you elaborate on what you mean by "a square area that is equivalent to different zoom heights"? Does this mean you want the square (height and width distances) to be the same regardless of the zoom level? – bdcoder Nov 28 '22 at 03:27

0 Answers0