Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show user's Lat and Long using google script

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 211
    Comment on it

    Hello User if want to show user's lat and long to screen then you can use the code as below:-

    First you have to create a html page and named it file.html and paste the following code in it.

    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Get my coordinates</p>
    
    <button onclick="getLocation()">Try It</button>
    
    <p id="demo"></p>
    
    </body>
    </html>
    

    Now you just have to paste the following code inside the header of your file

    <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>
    

    Now when you load this page a toggle button will appear and when user will click it a pop will come and show the coordinates of user. This script is driven by navigator.geolocation function. The fucntion showPosition(position) will break the coordinates into user's lat and long which is the final result that is to be shown.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: