TransWikia.com

Showing polyline corrdinates in text input

Geographic Information Systems Asked by Chivalry on February 27, 2021

This is my code:

map.on("click", function(e) {
    var latlng = e.latlng;
    document.getElementById("lat1").value = latlng.lat;
    document.getElementById("lng1").value = latlng.lng;
    console.log(latlng);
    });

How can I show all polyline coordinates, displaying in console.log, into text input?

enter image description here

One Answer

You need to append to the contents of the input elements, not overwrite them, so your code becomes

map.on("click", function(e) {
  var latlng = e.latlng;
  document.getElementById("lat1").value += latlng.lat;
  document.getElementById("lng1").value += latlng.lng;
  console.log(latlng);
});

Note the += instead of = in lines 2 and 3 of your function

Answered by til_b on February 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP