0

For some reason I'm getting undefined in the console, but I'm not sure why.

var mp = document.getElementById('map'), ms = mp.style, center = L.latLng(47.62, -122.3321), h = innerHeight-130;
var tl = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'});
ms.height = h+'px';
var map = L.map('map', {center:center, zoom:10, layers:[tl]});
// remove when deployed
map.on('click', function(e){
  console.log(e.latLng);
});

Yet, if I change console.log(e.latLng) to console.log(e), I'm seeing a result. According to their own documentation, it should work. Why doesn't it?

StackSlave
  • 10,613
  • 2
  • 18
  • 35

2 Answers2

1

e.latLng should have been e.latlng. Hard to see case sensitive issue.

StackSlave
  • 10,613
  • 2
  • 18
  • 35
0

Possible duplicate of How do I get the latlng after the dragend event in leaflet?.

latlng value is not in e.latlng but in e.target._latlng . Use console.

Community
  • 1
  • 1
Z. Bagley
  • 8,942
  • 1
  • 40
  • 52