3

I try to zoom to a number of km on a location (Paris, in my case), like this:

map.myCircle = circle;

// update radius
map.myCircle.radius = newRadius;

// update map - ZOOM
map.myCircle.setMap(null);
map.fitBounds(map.myCircle.getBounds());
map.myCircle.setMap(map);

CodePen

This gives enter image description here

As you can see, the fitBounds does not really fit the circle bounds.

When you increment (up-down) the radius, you can see that the map zoom does not change, but the circle radius changes.

Is there a way to synchronize the view zoom with the circle radius and make the circle touch the map margins?

duncan
  • 31,401
  • 13
  • 78
  • 99
serge
  • 13,940
  • 35
  • 121
  • 205
  • 1
    If you make your radius large or small enough, the zoom will adjust. For example, if you change your radius to less than 64km or more than 128km, the zoom will change to fit your circle. Seems like its working to me. – Andrew Mairose Nov 10 '15 at 18:23
  • I need to zoom *at each* radius change, not just by big steps – serge Nov 10 '15 at 18:23
  • Have you tried to create a [zoom listener](http://stackoverflow.com/a/2990316/668148)? – Bogdan Kobylynskyi Nov 10 '15 at 18:24
  • @BogdanKobylinsky: I tried in the codePen, but don't see any difference... – serge Nov 10 '15 at 18:48
  • 1
    @Serge the map zoom level doesn't allow you to adjust in tiny increments that you'd need if you wanted the bounds to exactly fit your radius, if you're just adjusting it by 1km at a time. – duncan Nov 10 '15 at 19:30
  • 2
    @duncan is right. But the documentation is not very clear. I think instead of saying *Sets the viewport to contain the given bounds* it should say *Sets the viewport to contain the given bounds using the most appropriate zoom level*. Or something like that ;-) – MrUpsidown Nov 11 '15 at 16:16
  • 1
    As for me, the zoom for the circle in the provided screen (65km) is not very *appropriate*... – serge Nov 12 '15 at 09:10
  • hey, did you solve this problem ? – MayK Nov 20 '15 at 15:29
  • 1
    @MayK I think there is no solution, as I understood the google map zoom is "step by step", not continuous... so there is a max zomm, say 1km, the others will be 2km, 4km, 8 km... so there is any possibility to set a 5km zoom... – serge Nov 20 '15 at 16:37

0 Answers0