Skip to content

Instantly share code, notes, and snippets.

@r1d3rzz
Created February 27, 2025 03:41
Show Gist options
  • Save r1d3rzz/25f00607e710bbbbb51044d479544c7e to your computer and use it in GitHub Desktop.
Save r1d3rzz/25f00607e710bbbbb51044d479544c7e to your computer and use it in GitHub Desktop.
Get Current Location
if ("geolocation" in navigator) {
// Geolocation is supported
navigator.geolocation.getCurrentPosition(
(position) => {
// Success callback
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
console.log(`Latitude: ${latitude}, Longitude: ${longitude}`);
},
(error) => {
// Error callback
console.error("Error getting location:", error.message);
}
);
} else {
// Geolocation is not supported
console.error("Geolocation is not supported by this browser.");
}
// output => Latitude: 16.*****, Longitude: 96.******
// example usage https://www.google.com/maps?q=16.*****,96.******
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment