Using HTML Geolocation with the javascript programming language is very easy.
The example uses the navigator.geolocation and gets all data for your geolocation.
Into your HTML page add this javascript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <script> function mapServiceProvider(lat, long) { document.writeln("Your geolocation position is:<br>") document.writeln("Latitude = "+lat+"; Longitude = "+long); } if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function (position) { mapServiceProvider(position.coords.latitude,position.coords.longitude); }, // next function is the error callback function (error) { switch(error.code) { case error.TIMEOUT: alert ('Timeout'); break; case error.POSITION_UNAVAILABLE: alert ('Position unavailable'); break; case error.PERMISSION_DENIED: alert ('Permission denied'); break; case error.UNKNOWN_ERROR: alert ('Unknown error'); break; } } ); //} } else { alert("Error: geolocation not supported in your browser!"); } </script> |
The result can be found at my codepen account.