locked
how to create session to Latitude and  Longitude RRS feed

  • Question

  • User1456523893 posted

    hello

    when run this script and get Latitude and  Longitude

    then i want get value in  session  asp.net vb

    <p id="demo"></p>

    <script>
    var x = document.getElementById("demo");

    function getLocation() {
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
    } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
    }
    }

    function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
    }
    </script>

    Sunday, December 16, 2018 12:38 PM

All replies

  • User61956409 posted

    Hi bryar,

    when run this script and get Latitude and  Longitude

    then i want get value in  session  asp.net vb

    You can try to maintain the Latitude and Longitude in a asp:HiddenField control, and then you can access the value (Latitude and Longitude that you saved) of sp:HiddenField control from your vb code on server side.

    <p id="demo"></p>
    <asp:HiddenField ID="hf_location" runat="server" Value="" />
    <script>
        var x = document.getElementById("demo");
    
        function getLocation() {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(showPosition);
            } else {
                x.innerHTML = "Geolocation is not supported by this browser.";
            }
        }
    
        function showPosition(position) {
            x.innerHTML = "Latitude: " + position.coords.latitude +
                "<br>Longitude: " + position.coords.longitude;
    
            //maintain the Latitude and Longitude in a asp:HiddenField control 
            document.getElementById("hf_location").value = position.coords.latitude + "|" + position.coords.longitude;
        }
    </script>

    With Regards,

    Fei Han

    Monday, December 17, 2018 2:12 AM