Skip to content

Latest commit

 

History

History
40 lines (18 loc) · 1.03 KB

Geolocation in HTML.md

File metadata and controls

40 lines (18 loc) · 1.03 KB

Geolocation

h

HTML provides built-in support for getting the user's location using the Geolocation API. This API allows you to get the user's latitude and longitude, as well as their altitude and speed, if available. You can use this information to provide location-based services, such as finding nearby restaurants or weather information.

Here's an example of how to get the user's location:

Get Location

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