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>
	<title>Geolocation API Example</title>
		function getLocation() {
			if (navigator.geolocation) {
			} else {
				alert("Geolocation is not supported by this browser.");

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

2 Responses

Leave a Reply

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