Ali Hasanzade
Ali Hasanzade

Reputation: 151

Android : determine zoom level from circle

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

Answers (1)

Ali Hasanzade
Ali Hasanzade

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

Related Questions