Issue checking for geolocation
This commit is contained in:
parent
5691f9ed97
commit
db2d39637d
1 changed files with 44 additions and 18 deletions
|
|
@ -1,30 +1,56 @@
|
||||||
const getGeolocation = (setGeolocationData) => {
|
const getGeolocation = (setGeolocationData) => {
|
||||||
new Promise((showPosition, showError) => {
|
new Promise((showPosition, showError) => {
|
||||||
navigator.geolocation.getCurrentPosition(showPosition, showError, { enableHighAccuracy: true });
|
navigator.geolocation.getCurrentPosition(showPosition, showError, {
|
||||||
}).then(async (position) => {
|
enableHighAccuracy: true,
|
||||||
const geocode = await getGeocode(position.coords.latitude, position.coords.longitude);
|
});
|
||||||
|
})
|
||||||
|
.then(async (position) => {
|
||||||
|
const geocode = await getGeocode(
|
||||||
|
position.coords.latitude,
|
||||||
|
position.coords.longitude
|
||||||
|
);
|
||||||
|
|
||||||
|
const issues = checkIssues();
|
||||||
|
console.log(issues);
|
||||||
|
console.log(navigator.geolocation.getCurrentPosition);
|
||||||
|
|
||||||
setGeolocationData([
|
setGeolocationData([
|
||||||
getObj('Latitude', position.coords.latitude),
|
getObj('Latitude', position.coords.latitude, issues),
|
||||||
getObj('Longitude', position.coords.longitude),
|
getObj('Longitude', position.coords.longitude, issues),
|
||||||
getObj('Accuracy', position.coords.accuracy),
|
getObj('Accuracy', position.coords.accuracy, issues),
|
||||||
getObj('Altitude', position.coords.altitude),
|
getObj('Altitude', position.coords.altitude, issues),
|
||||||
getObj('Altitude accuracy', position.coords.altitudeAccuracy),
|
getObj('Altitude accuracy', position.coords.altitudeAccuracy, issues),
|
||||||
getObj('Heading', position.coords.heading),
|
getObj('Heading', position.coords.heading, issues),
|
||||||
getObj('Speed', position.coords.speed),
|
getObj('Speed', position.coords.speed, issues),
|
||||||
getObj('Reverse geocoding', geocode),
|
getObj('Reverse geocoding', geocode, issues),
|
||||||
]);
|
]);
|
||||||
})
|
})
|
||||||
.catch((e) => setGeolocationData(e.message));
|
.catch((e) => setGeolocationData(e.message));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGeocode = (lat, long) => fetch(`https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${long}&key=AIzaSyByyRWGncal9iAq1-3Ek2WQ3ROLw9bCS-8`)
|
const checkIssues = () => {
|
||||||
|
console.log(navigator.geolocation.getCurrentPosition.toString());
|
||||||
|
if (
|
||||||
|
!navigator.geolocation.getCurrentPosition
|
||||||
|
.toString()
|
||||||
|
.includes('[native code]')
|
||||||
|
) {
|
||||||
|
return "Failed navigator.geolocation.getCurrentPosition.toString().includes('[native code]')";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGeocode = (lat, long) =>
|
||||||
|
fetch(
|
||||||
|
`https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${long}&key=AIzaSyByyRWGncal9iAq1-3Ek2WQ3ROLw9bCS-8`
|
||||||
|
)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => data.results[0].formatted_address);
|
.then((data) => data.results[0].formatted_address);
|
||||||
|
|
||||||
const getObj = (key, value) => ({
|
const getObj = (key, value, issues) => ({
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
issues: [],
|
issues: [issues].filter(Boolean),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default getGeolocation;
|
export default getGeolocation;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue