Using Accuweather API to create a weather app. I believe I have messed up somewhere with syntax but I can't figure out where I went wrong. Any advice?
Line 26:100: 'lat' is not defined no-undef
Line 26:109: 'long' is not defined no-undef
import { useEffect, useState } from "react";
function Location() {
let [data, setData] = useState([]);
const key = process.env.REACT_APP_API_KEY;
useEffect(() => {
if (!data) return;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction, console.log());
} else {
alert(
"It seems like Geolocation, which is required for this page, is not enabled in your browser. Please use a browser that supports it."
);
}
function successFunction(latlong) {
const lat = latlong.coords.latitude;
const long = latlong.coords.longitude;
console.log("latlong = " + lat + ", " + long);
}
fetch(
`http://dataservice.accuweather.com/locations/v1/cities/geoposition/search?apikey=${key}&q=${lat}%2C${long}`
)
.then((response) => response.json())
.then((data) => setData(data))
.catch((err) => console.log(`Error Meassage ${err}`));
}, []);
console.log("location key = ", data.Key);
}
export default Location;