This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

get the longitude and latitud and show on the inputbox

0

hi, i show the user current location in map, i need to show user longitude and latitud on input box.tnx for help

myscript:

<script>
    var map = L.map('map').fitWorld();

    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=token', {
        maxZoom: 18,
        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
            '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
            'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
        id: 'mapbox.streets'
    }).addTo(map);

    function onLocationFound(e) {
        var radius = e.accuracy / 2;

        L.marker(e.latlng).addTo(map)
            .bindPopup("You are within " + radius + " meters from this point").openPopup();

        L.circle(e.latlng, radius).addTo(map);
    }

    function onLocationError(e) {
        alert(e.message);
    }

    map.on('locationfound', onLocationFound);
    map.on('locationerror', onLocationError);

    map.locate({setView: true, maxZoom: 16}); 
</script>

asked 16 Nov '19, 13:31

eurus's gravatar image

eurus
11335
accept rate: 0%

edited 16 Nov '19, 13:32

Source code available on GitHub .