Answers for "how to get elevation with google elevation api"

0

how to get elevation with google elevation api

const [currentLatitude, setCurrentLatitude] = useState(0);
const [currentLongitude, setCurrentLongitude] = useState(0);
const [currentElevation, setCurrentElevation] = useState(0);

  useEffect( async () => {
    try {
      const res = await fetch(`https://maps.googleapis.com/maps/api/elevation/json?locations=${currentLatitude},${currentLongitude}&key={your_API}`);
      const data = await res.json()
      const currentElevation = JSON.stringify(data.results[0].elevation);
      setCurrentElevation(currentElevation);
    } catch (error) {
      console.log(error)
    }
}, [currentLongitude]);
Posted by: Guest on April-23-2021

Browse Popular Code Answers by Language