These two methods to fetch location are common:
export const getLocation = (options) => {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(resolve, reject, options);
});
}
export const getLocationData = async (): Promise<LocationData> => {
let locationData;
if (navigator.geolocation && navigator.geolocation.getCurrentPosition) {
try {
console.log("ENTERED");
locationData = await getLocation({ enableHighAccuracy: true });
console.log("success locationdata", locationData);
} catch (e) {
locationData = null;
console.log("catch locationdata", e);
}
}
const postLocationData= locationData ? {
timestamp: locationData.timestamp,
accuracy: locationData.coords ? locationData.coords.accuracy : 0,
latitude: locationData.coords ? locationData.coords.latitude : 0,
longitude: locationData.coords ? locationData.coords.longitude : 0
} : null;
return postLocationData;
}
This method is in a different component
import { getLocationData } from '../../CommonMethods';
async componentDidMount() {
let locationData = await getLocationData();
this.props.requestGameList(null, null, locationData);// requestGameList();
this.props.requestContentCard(locationData);// request content cards
}
I have some games based on the GeoLocation and some not based on GeoLocation which should be loaded, and this works when the location service is ON, but when the location service is OFF the Killing the browser(Safari) by double tapping the Home Button and Swiping the Browser is not loading any games in the browser. While doing the console.log, I can see the thread till console.log(“ENTERED”);, after that what I assume is either it has to be success or reject, However, in my case (i.e. When Location Service is set to OFF) should reject and should go to catch section and return null. I can see the console.log(“ENTERED”) but after that nothing happens. The thread is not going to catch. But the same code works with the same scenario in chrome in iOS. What could be the reason behind it and why Safari browser is behaving differently?