Created
February 27, 2025 03:41
-
-
Save r1d3rzz/25f00607e710bbbbb51044d479544c7e to your computer and use it in GitHub Desktop.
Get Current Location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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