function getLocation(successCallback, errorCallback) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {
maximumAge: 3000,
timeout: 60000,
enableHighAccuracy: true,
});
} else {
// Handle error
}
}
function getGeolocationData() {
// Call the getLocation() function and pass in callback functions.
getLocation((position) => {
//The user's position is available.
const JSONobj = {
lat: position.coords.latitude,
long: position.coords.longitude,
success: true,
error: null,
message: "",
};
const strRetJSONobj = JSON.stringify(JSONobj);
console.log(strRetJSONobj); //...OK
return ("OK"); //returns null in B4J
}, (error) => {
// The user's position could not be determined.
const JSONobj = {
lat: null,
long: null,
success: false,
error: error.code,
message: error.message,
};
const strRetJSONobj = JSON.stringify(JSONobj);
console.log(strRetJSONobj); //...OK
return ("!OK"); //returns null in B4J
});
}