I have a Java script that returns user geolocation, I tested the script with Chrome developer tools and it runs with no problems, the problem is it returns an empty result to B4J server!
Your help is appreciated to solve this problem.
TIA
Your help is appreciated to solve this problem.
TIA
HTML page:
<button class="btnlocation" type="submit" id="location" >Location</button>
Java Script:
function getlocation() {
// var JSONobj = {};
if (navigator.geolocation) {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(function (position) {
JSONobj = {
lat: position.coords.latitude,
long: position.coords.longitude,
success: true,
error: null,
message: '',
};
resolve(JSONobj);
}, function (error) {
JSONobj = {
lat: null,
long: null,
success: false,
error: error.code,
message: error.message,
};
//reject(error);
resolve(JSONobj);
},
//options
{
maximumAge: 3000,
timeout: 60000,
enableHighAccuracy: true,
});
});
} else {
// Handle error
}
}
async function getGeolocationData() {
const retJSONobj = await getlocation();
console.log(retJSONobj); //logs OK in console
return (retJSONobj);
// Use the geolocation data in your application
}
Chrome Console:
{
"lat": xx.xx,
"long": xx.xx,
"success": true,
"error": null,
"message": ""
}
B4J:
Sub Location_Click(Params As Map)
Dim f As Future = ws.RunFunctionWithResult("getGeolocationData", Null)
Log(f.Value)
ws.Flush
'logs these two lines,
'Waiting for value (100 ms)
'{}
End Sub