distante distante - 1 year ago 128
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);

is a valid map object created by

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)

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

TypeError: Cannot read property 'lat' of null

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download