4

in my application i have a MapView.

i want to change the zoom of the map according to the radius the user set. i've found the answer in this link, but the problem is that the function consider only the screen's width.. i want to height to be consider too.

for instance: if i want to see radius of 1km - the function in the link will show me a width of 1km but not a height of 1km.. it is really important for me that it will show it on both width and height even if when height is 1km the width is 1.5km

how can i do it ?

2
  • Could you get a way to do this? Commented Jul 26, 2013 at 13:27
  • not really... the link in the question is the best answer i found so far.. Commented Jul 26, 2013 at 15:52

1 Answer 1

4

Here is the working code and with accurate result.

1) Make a circle on object with desired radius

Circle circle = mGoogleMap.addCircle(new CircleOptions().center(new LatLng(latitude, longitude)).radius(getRadiusInMeters()).strokeColor(Color.RED)); circle.setVisible(true); getZoomLevel(circle); 

2) Pass that object to this function and set the zoom level Here's a link

public int getZoomLevel(Circle circle) { if (circle != null){ double radius = circle.getRadius(); double scale = radius / 500; zoomLevel =(int) (16 - Math.log(scale) / Math.log(2)); } return zoomLevel; } 
Sign up to request clarification or add additional context in comments.

1 Comment

what is 500 in this case ? what is 16 in this case ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.