question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Leaflet throwing "Uncaught TypeError: Cannot read property 'lat' of undefined" on valid LatLngBounds - fitbounds method, browserify

See original GitHub issue

I can’t work this out, I am providing map.fitBounds with what appears to be a perfectly valid LatLngBounds object.

console.log(bounds) gives me

L.LatLngBounds {_southWest: L.LatLng, _northEast: L.LatLng, extend: function, pad: function, getCenter: function…}

bounds.isValid() is true.

Yet when I try to use that same object with fitbounds I’m getting this elusive

Cannot read property ‘lat’ of undefined"

It might be worth mentioning i’m using browserify?

If I provide fitbounds with an array instead (as shown below), it works fine!

        console.log(center);
                console.log(bounds);
                console.log(data);

                _.forEach(data.hits, function(hit, i) {
                    var coords = hit._source.location.coords,
                        latLon = [coords.lat, coords.lon];

                    bounds.extend(latLon);
                });

                console.log('final bounds');
                console.log(bounds);

                mapObj.fitBounds([
                    [-38.1249603,145.17332020000003],
                    [-38.1770225,145.10952610000004]
                ]);

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
ukaccount123commented, Feb 2, 2016

Is this a concurrency issue where you are calling .getBounds() too early, and shows up on different machines based on the size of the dataset and the speed of the machine?

@damiendevienne does waiting for the “ready” event work for you?:

za.on('ready', function(e) {
        map.fitBounds(za.getBounds());
});
1reaction
perliedmancommented, Nov 14, 2017

@galileopy if you look at the issue title, it says this is about LatLngBound, fitBounds and browserify. It’s not about Polylines or MultiPolylines.

The issue you’re having has to do with a marker that has not LatLng set.

Stepping through the code of Leaflet.pm, it looks pretty clear that it can’t handle MultiPolylines, since it assumes a polyline is a single array of LatLngs, not mutiple arrays.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet throwing "Uncaught TypeError: Cannot read property ...
So the problem is that none of the values I have are null; how can a marker have a null latlng if when...
Read more >
typeerror: cannot read properties of undefined (reading 'lat')
Note: I have tried this plugin on these leaflet versions (1.0.0 to 1.2.0) which are working fine. But with the latest leaflet version,...
Read more >
Cannot read property 'lat' of undefined - abc-baltin.de
javascript - Leaflet throwing "Uncaught TypeError: Cannot read property 'lat' of undefined" when adding new marker to map - Stack Overflow.
Read more >
Call map.fitBounds(bounds); produce error "Uncaught ... - GitLab
fitBounds (bounds); produce error "Uncaught TypeError: Cannot read property 'getZoom' of undefined". Error throws in _removeTile method on ...
Read more >
L.LatLngBounds - WRLD3D
All Leaflet methods that accept LatLngBounds objects also accept them in a ... for zooming the map to fit a particular set of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found