11

I've tried map.fitBounds(geojsonFeature.getBounds()); and I get this error:

geojsonFeature.getBounds() is not a function.

Here is the code: http://jsfiddle.net/0aqxktov/

What is going wrong here?

Thanks in advance.

Gerardo Furtado
  • 100,839
  • 9
  • 121
  • 171
Mike Johnson Jr
  • 776
  • 1
  • 13
  • 32

1 Answers1

18

Your variable geojsonFeature is just an object, there is no method named getBounds() there, as you can easily check.

Instead of that, give your geoJSON layer a name...

var feature = L.geoJson(geojsonFeature).addTo(map);

And use that to call getBounds():

map.fitBounds(feature.getBounds());

Here is the updated JSFiddle: http://jsfiddle.net/qofrgm2k/

Gerardo Furtado
  • 100,839
  • 9
  • 121
  • 171