1

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;
}
Ali Hasanzade
  • 151
  • 15
  • If you want to fit your circle into the map, you can try this method: http://stackoverflow.com/a/17278527/4195406 – ztan Mar 10 '15 at 16:28

1 Answers1

3

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 ;
}
Ali Hasanzade
  • 151
  • 15