I am using React-Native's Location.getCurrentPositionAsync() to retrieve a user's location when they arrive at a site and also when they depart from the site. However, even though the user is in the exact same location the geolocation data is different.
I am using BingMaps to pull the address and a map of the location and the address is sometimes several blocks away from the user's actual location. I set the location accuracy to LocationAccuracy.Highest but still get some odd results.
Any help fixing this is much appreciated!
`
export async function GetPosition() {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
console.log('Permission to access location was denied');
return;
}
return new Promise((resolve, reject) => {
Location.getCurrentPositionAsync({accuracy:LocationAccuracy.Highest}).then(pos => {
console.log(pos); resolve(getCoordsFromPosition(pos));
}, reject);
});
}
`
`
function getCoordsFromPosition(position) {
const coords = position.coords;
return coords;
}
`
function getAddressByPoint(address) {
const name = address.resourceSets[0].resources[0].name;
return name;
}
`
export async function FindLocationByPoint (latitude, longitude) {
return new Promise(async (resolve, reject) => {
await fetch("https://dev.virtualearth.net/REST/v1/Locations/"+ latitude + "," + longitude + "?key=" + bing_maps_key, {
method: 'GET',
headers: new Headers({
Accept: 'application/json'
}),
}).then(res => res.json()).then(data => {
console.log(data);
resolve(getAddressByPoint(data));
}, reject)
});
}
`
`
var startPos = await GetPosition().then((res) => startPos = res);
var startLoc = await FindLocationByPoint(startPos.latitude, startPos.longitude).then((data) => startLoc = data);
var stopPos = await GetPosition().then((res) => stopPos = res);
var stopLoc = await FindLocationByPoint(stopPos.latitude, stopPos.longitude).then((data) => stopLoc = data);
`
I tried setting location accuracy to the highest setting and expected accuracy within a few addresses but I am getting addresses several blocks away