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);
}
`