I successfully added a feature to display the LAT LON readout of the cursor location on my website by following the tutorial provided in This Mapbox GL JS Tutorial
However, the output I receive is in this format:
{"lng:-74.949147382928,"lat":40.43829220439884}
In the tutorial example, they demonstrate this format. Is there a way to extract only the LAT and LON values? Ideally, I want the output to look like this:
-74.949147382928, 40.43829220439884
Although I am not very skilled with javascript, I attempted to use substring function to modify the output as follows. However, my attempt was unsuccessful. If possible, is there an easier method to achieve this? The experimental code snippet I tried is shown below, but it seems that using substring in this context does not work. In summary, I am seeking any solution that can deliver just the LAT and LON values.
Unsuccessful Code :
topleftmapbox.on('mousemove', function (e) {
document.getElementById('info').innerHTML =
JSON.stringify(e.lngLat.substring(6,17)); // aiming to extract only the values
});