GPX on OSM - showing track name

I have a gpx file with several tracks. How can I display the name of the track that I have clicked on? It always gives the name of the first track in the file.

The code I use is

.on(‘click’, function(e) {
//map.fitBounds(e.target.getBounds());
alert(e.target.get_name());
}

Part of the file:

type or paste code here
<?xml version="1.0"?> 2023-02-08 Taronga Zoo Wharf to Mosman Bay 1 of 989 1 2023-01-25 Cremorne Wharf to Old Cremorne 1 of 2 1
<trkpt lat="-33.8477181" lon="151.2311488">
</trkpt>
<trkpt lat="-33.8484844" lon="151.2328439">
</trkpt>
<trkpt lat="-33.8474864" lon="151.2312775">
</trkpt>
<trkpt lat="-33.8463993" lon="151.23095570000001">
</trkpt>
<trkpt lat="-33.8447063" lon="151.230462100000011">
</trkpt>
<trkpt lat="-33.8442964" lon="151.230118800000014">
</trkpt>
<trkpt lat="-33.8432984" lon="151.229754">
</trkpt>
<trkpt lat="-33.8425855" lon="151.229754">
</trkpt>
<trkpt lat="-33.8421578" lon="151.230140299999988">
</trkpt>

<trkpt lat="-33.8420152" lon="151.2300974">
</trkpt>
<trkpt lat="-33.8408567" lon="151.2302905">
</trkpt>
Thanks

The gpx data is not pasting properly. It seems to be analyzing the data rather than posting it verbatim. I’m new to this and can’t find where to get help in posting things.
Thanks

What software are you using?

1 Like

HTML/Javascript running on xampp with
https://unpkg.com/leaflet@1.8.0/dist/leaflet.js

https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js
https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.7.0/gpx.min.js"

I’ve done some more reading up on gpx and it doesn’t appear what I want to do is possible. The leaflet plug-in ignores all tags except the first.
Thanks

In Discourse forums like this one, it is probably easiest to use Markdown formatting. In your particular case, see the lowest example for code block, i.e. put three backquotes (```) on line by itself before the gpx sample, and same three backquotes on line by itself after the gpx sample.

Hi @Ronald_Besdansky,

there seems to be a solution for your problem. It doesn’t look complicated: