This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
How to get current GPS Position within a WebView
Camilo edited this page May 29, 2021
·
2 revisions
This is an example using the $geo.get
action and $agent
service.
- https://jasonelle-archive.github.io/docs/legacy/actions/#geo
- https://jasonelle-archive.github.io/docs/legacy/agents/
{
"$jason": {
"head": {
"actions": {
"fetchGPS": {
"type": "$geo.get",
"options": {
"distance": "1000"
},
"success": {
"type": "$agent.request",
"options": {
"id": "$webcontainer",
"method": "receiveGPS",
"params": ["{{$jason.coord}}"]
},
"success": {
"type": "$util.alert",
"options": {
"title": "GPS Fetched",
"description": "LAT: {{$jason.lat}} LONG:{{$jason.long}}"
}
}
}
}
}
},
"body": {
"background": {
"type": "html",
"url": "file://index.html",
"action": {
"type": "$default"
}
}
}
}
}
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
const receiveGPS = (coords) => {
console.log("GOT COORDS");
const coordinates = coords.split(",");
const gps = {
lat: coordinates[0],
long: coordinates[1]
};
const element = document.getElementById("gps-location");
element.innerHTML = JSON.stringify(gps);
// This is important to trigger the success in the callstack
$agent.response(gps);
};
const fetchGPS = () => {
console.log("FETCHING GPS");
$agent.trigger("fetchGPS");
};
</script>
</head>
<body>
THE GPS LOCATION IS <span id="gps-location"></span>
<br>
<button onClick="fetchGPS()">FETCH GPS</button>
</body>
</html>
- Telegram: https://t.me/jasonelle
- Website: https://jasonelle.com
- Additional: https://jasonelle-archive.github.io/docs/legacy/