Get started with geo-location-javascript CDN

MIT licensed

Geo-Location-JS is a lightweight library for working with HTML5 Geolocation API in JS.

Tags:
  • geolocation

Stable version

Copied!

How to start using geo-location-javascript CDN


<!DOCTYPE html>
<html>
<head>
    <title>Get started with geo-location-javascript CDN - cdnhub.io</title>
    <script src="https://cdn.cdnhub.io/geo-location-javascript/0.4.8/geo-min.js"></script>
</head>
<body>
    <button id="getLocation">Get Location</button>
    <div id="locationOutput"></div>

    <script>
        const locationButton = document.getElementById('getLocation');
        const locationOutput = document.getElementById('locationOutput');

        if (navigator.geolocation) {
            locationButton.addEventListener('click', () => {
                navigator.geolocation.getCurrentPosition(position => {
                    const pos = {
                        lat: position.coords.latitude,
                        lng: position.coords.longitude
                    };

                    locationOutput.innerHTML = `<p>Your location:</p><p>Latitude: ${pos.lat}</p><p>Longitude: ${pos.lng}</p>`;
                });
            });
        } else {
            locationOutput.innerHTML = 'Geolocation is not supported by this browser.';
        }
    </script>
</body>
</html>
Copied!
Copied!

All versions