This geolocation API allows websites to retrieve a user’s location information (latitude and longitude) using their device’s GPS or IP address.

Code Example:

<!DOCTYPE html>
<html>
<head>
	<title>Geolocation API Example</title>
	<script>
		function getLocation() {
			if (navigator.geolocation) {
				navigator.geolocation.getCurrentPosition(showPosition);
			} else {
				alert("Geolocation is not supported by this browser.");
			}
		}

		function showPosition(position) {
			alert("Latitude: " + position.coords.latitude + 
			"\nLongitude: " + position.coords.longitude);
		}
	</script>
</head>
<body>
	<button onclick="getLocation()">Get Location</button>
</body>
</html>

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *