Reputation: 151
I am using this code for determining zoom level from circle , but it's not returning valid zoom level,what is the problem?
I want to set map zoom level for display all part of circle.
public float getZoomLevel(Circle circle)
{
float zoomLevel = 11;
if (circle != null) {
double radius = circle.getRadius() + circle.getRadius() / 2;
double scale = radius / 500;
zoomLevel = (float) (16 - Math.log(scale) / Math.log(2));
}
return zoomLevel;
}
Upvotes: 1
Views: 975
Reputation: 151
I fixed it with Math.floor
and using integer instead of float
public int getZoomLevel(Circle circle)
{
int zoomLevel = 11;
if (circle != null)
{
double radius = circle.getRadius();
double scale = radius / 500;
zoomLevel = (int) Math.floor((16 - Math.log(scale) / Math.log(2)));
}
return zoomLevel ;
}
Upvotes: 3