Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to locate user postion using HTML5 Geolocation

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 118
    Comment on it

    You can easily locate user position using Geolocation API. It is used to get the geographical position of user. However it is much more accurate for devices like iphone with GPS. We can find the user position by using etCurrentPosition() method. So first check if Geolocation is supported if yes run the getCurrentPostion() method if successful it returns a coordinate function of an object which is specified in parameter showposition which calls the function and output the latitude and longitude.

    <script>
    var x = document.getElementById("check");
    function getLocation() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else {
            x.innerHTML = "Geolocation is not supported.";
        }
    }
    function showPosition(position) {
        x.innerHTML = "Latitude: " + position.coords.latitude +
        "<br>Longitude: " + position.coords.longitude;
    }
    </script>
    

 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: