Saturday, July 29, 2023

Geolocation Vanilla Javascript

<html>

<head>

    <title>

        GEO

    </title>

</head>

<body>

    <button>GET LOCATION</button>

</body>

<script>

    const button = document.querySelector("button");

    button.addEventListener("click", (e) => {

        navigator.geolocation.getCurrentPosition(position => {

            const { latitude, longitude } = position.coords;

            console.log(`https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${latitude}&lon=${longitude}`)

            const url = `https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${latitude}&lon=${longitude}`;

            fetch(url)

            .then(response => response.json())

            .then((data) => { console.log(data) })

            .catch((error) => {console.log(error)});

        })

    })

</script>

</html> 

No comments:

Post a Comment

Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...