I have the following code that takes the user's location from a google api, the detail I have is that the accuracy is too high, for example accuracy: 2600.670416166183, I don't know if someone knows how to solve this error, it would be very useful
const useGeoLocation = () => {
const [location, setLocation] = useState({
loaded: true,
coordinates: {
lat: "",
lng: "",
},
aceptacion: null,
});
const onSuccess = (location) => {
console.log(location);
setLocation({
loaded: true,
coordinates: {
lat: resultado.location.lat,
lng: resultado.location.lng,
},
aceptacion:1
});
};
useEffect(() => {
const url = `https://www.googleapis.com/geolocation/v1/geolocate?key=......`;
const http = new XMLHttpRequest();
http.open("POST", url);
http.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
let resultado = JSON.parse(this.responseText);
let latitude = resultado.location.lat;
let longitude = resultado.location.lng;
setLocation({
loaded: true,
coordinates: {
lat: resultado.location.lat,
lng: resultado.location.lng,
},
aceptacion:1
});
console.log(resultado);
return resultado
}
}
http.send();
}, []);
return location;
}; export default useGeoLocation;