We have distance search filter. It has a map viewport that allow to set base marker and a input text box that allows enter distance in kilometers.
We then add a circle to show this distance on the map.
How can I zoom the map so it fits the circle?
The default zoom level is set to 0. You can change the zoom level of the map using simple steps. Step 1 Go to Add or Edit Map page . Step 2 Select 'Default zoom level' in the 'Map Information section'.
Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map for touchscreen devices.
A google.maps.Circle
has a getBounds()
method which returns the LatLngBounds
of the circle. You may use this bounds as argument for google.maps.Map.fitBounds()
If using a circle, you can do this:
map.fitBounds(circle.getBounds());
...at the end of the init-function.
http://jsfiddle.net/doktormolle/MHLjy/
For multiple circles use union instead of extend:
var bounds = new google.maps.LatLngBounds(); $.each(circles, function(index, circle){ bounds.union(circle.getBounds()); }); map.fitBounds(bounds);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With