Getting your location with HTML5 geolocation

The HTML5 specification includes support for geolocation for determining an approximation of your position. JavaScript is used in this example to get and display your position.

<!DOCTYPE html>

    <title>Geolocation with HTML5</title>

    <script type="text/javascript">
        function getMyLocation(){
                    var myLocation = document.getElementById('myLocation');
                    myLocation.innerHTML = 'Latitude: ' + location.coords.latitude +
                                            ' Longitude: ' + location.coords.longitude;


<body onload="getMyLocation();">

<div id="myLocation">Fetching your location...</div>





This entry was posted in JavaScript and tagged , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?