I implement the mechanism for the user to mark a map with a click. I need to extract the data of latitude and longitude of this marker, I output latLng - empty, latit- displays the value. What could be the error? enter image description here

The obtained values ​​of latitude and longitude must be stored in the database in the scheme:

var sightsSchema = mongoose.Schema({ sight:{ longit: Number, latit: Number }, oversight: {...} }); 

Adding a label to the card by clicking:

  var map2; function initMap() { map2 = new google.maps.Map(document.getElementById('locationSight'), { zoom: 10, center: {lat: 48, lng: 43} }); map2.addListener('click', function (e) { placeMarkerAndPanTo(e.latLng, map2); }); } function placeMarkerAndPanTo(latLng, map2) { var marker = new google.maps.Marker({ position: latLng, map: map2 }); map2.panTo(latLng); var latit = latLng.lat(); var longit = latLng.lng(); console.log('latit', latit); console.log('latLng', latLng); document.querySelector('.inputLat').value = latit; document.querySelector('.inputLng').value = longit; } 
  • Specify which card is in question? - Anatoly Shevelev
  • @ anatoliyishev, googlemap - vita_run
  • one
  • why does latLng appear in the console and not longit ? - Grundy

0