Questions tagged [fitbounds]

92 questions
220
votes
24 answers

Google Maps API v3: Can I setZoom after fitBounds?

I have a set of points I want to plot on an embedded Google Map (API v3). I'd like the bounds to accommodate all points unless the zoom level is too low (i.e., zoomed out too much). My approach has been like this: var bounds = new…
chris
  • 16,324
  • 9
  • 37
  • 40
104
votes
17 answers

Google Maps v3 fitBounds() Zoom too close for single marker

Is there a way to set a max zoom level for fitBounds()? My problem is that when the map is only fed one location, it zooms in as far as it can go, which really takes the map out of context and renders it useless. Perhaps I am taking the wrong…
Codey W
  • 1,041
  • 2
  • 7
  • 3
91
votes
9 answers

Google Maps v3: Enforcing min. zoom level when using fitBounds

I'm drawing a series of markers on a map (using v3 of the maps api). In v2, I had the following code: bounds = new GLatLngBounds(); ... loop thru and put markers on map ... bounds.extend(point); ... end looping …
chris
  • 36,094
  • 53
  • 157
  • 237
33
votes
2 answers

fitbounds() in Google maps api V3 does not fit bounds

I'm using the geocoder from Google API v3 to display a map of a country. I get the recommended viewport for the country but when I want to fit the map to this viewport, it does not work (see the bounds before and after calling the fitBounds function…
jul
  • 721
  • 1
  • 9
  • 18
21
votes
3 answers

How do you call fitBounds() when using leaflet-react?

I cannot figure out how to call fitBounds() on the Leaflet map. If I was just using vanilla leaflet, this solution would work perfectly: Zoom to fit all markers in Mapbox or Leaflet Unfortunately, I am using react-leaflet. Here is the solution if I…
Dox
  • 571
  • 1
  • 5
  • 15
14
votes
7 answers

google maps API 3 zooms out on fitBounds

I've run into a problem where calling map.fitBounds seems to zoom out. I'm trying to use the backbone.js router to save the map bounds in the url. I want to be able to bookmark the url and later have the map look exactly the same. I noticed calling…
codr
  • 894
  • 4
  • 11
  • 17
12
votes
2 answers

Google Maps API v3 - Geocoder results issue with bounds

Goal: I want to have a custom search (geocode) function and be able to list and click each result and display it on the map. Wanted: Adjust map bounds / zoom level accordingly, i.e. searching for "MA, USA" should zoom the map to let me see the whole…
MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
12
votes
2 answers

Calling map.fitBounds() Multiple Times in Google Maps API v3.0

I've just begun using the Google Maps API (v3.0) and have had a good deal of success so far. I am loading a set of objects with Latitude & Longitude values from a database, passing them into my script, and looping over them in the script in order to…
egoodberry
  • 2,746
  • 2
  • 26
  • 29
10
votes
12 answers

Google Maps API V3 fitbounds() zooms out but never in

I've created a quite complex store locator of sorts. The user enters their zip and a table returns results with corresponding markers on a map. They can page through results and the markers move further and further out and the fitbounds() function…
abemonkey
  • 199
  • 1
  • 3
  • 14
9
votes
5 answers

fitBounds() shows whole earth (if map is first hidden and then shown)

I have a bunch or markers, and I want to show only the area containing them. I found a long list of similar questions (see at the bottom of the post for some), but none of the solutions works for me. The LatLngBounds is built correctly, but when I…
Stephan
  • 1,858
  • 2
  • 25
  • 46
8
votes
4 answers

Google Maps fitBounds is not working properly

I have a problem with googlemaps fitBounds functions. for (var i = 0; i < countries.length; i++) { var country = countries[i]; var latlng = new google.maps.LatLng(parseFloat(country.lat), parseFloat(country.lng)); mapBounds.extend(latlng);…
user160820
  • 14,866
  • 22
  • 67
  • 94
7
votes
1 answer

fitBounds of markers with Leaflet

I have a array of markers named markersand i add those markers in map using LeafletJs L.layerGroup(markers).addTo(map); Now i want to focus on a viewport that covers all markers var bounds = L.latLngBounds(markers); map.fitBounds(bounds, {…
Moshi
  • 1,385
  • 2
  • 17
  • 36
6
votes
4 answers

Flutter LatLngBounds not showing accurate place

I am trying to show all of my markers into the viewport using my flutter google maps. But it seems not working in my case. I have tried so far as below: _controller.animateCamera(CameraUpdate.newLatLngBounds( LatLngBounds( …
Enayet Hossain
  • 187
  • 1
  • 4
  • 14
6
votes
2 answers

Leaflet - Fitbounds and keep center

I'm using Leaflet with Mapbox and I'd like to set the view of the map so : all markers are visible the center is set to a specific point It's easy to do each points separately with setView and fitbounds but I don't know how to have both at the…
DevLR
  • 73
  • 1
  • 4
6
votes
4 answers

Google Maps map.getBounds() immediately after a call to map.fitBounds

I'm calling getBounds() directly after a call to fitBounds(), and I thought I'd get a valid bound back as the map recenters and zooms to fit the bounds. Unfortunately, getBounds() is returning nil. The code to reproduce this is as follows:
Codebeef
  • 43,508
  • 23
  • 86
  • 119
1
2 3 4 5 6 7