distante distante - 27 days ago 16
Javascript Question

L.latLng() created object throws "Invalid LatLng object" when used on setZoomAround()

Using the documentation example, I'm trying to zoom into an specific point. So I do this:

var latlng = L.latLng(50.5, 30.5);
$scope.map.setZoomAround(latlng);


$scope.map
is a valid map object created by
L.map()
.

I get this error:


Invalid LatLng object: (NaN, NaN)

at o.LatLng (leaflet.js:6)
at Object.unproject (leaflet.js:6)
at Object.pointToLatLng (leaflet.js:6)
at e.unproject (leaflet.js:6)
at e.layerPointToLatLng (leaflet.js:6)
at e.containerPointToLatLng (leaflet.js:6)
at e.setZoomAround (leaflet.js:6)



Doing
$scope.map.setZoomAround([50.5, 30.5])
throws the same error and
$scope.map.setZoomAround(50.5, 30.5)
throws:


TypeError: Cannot read property 'lat' of null

Answer

Double-check the parameters for the setZoomAround method, as it expects a zoom level to be specified.

Comments