Skip to content

Instantly share code, notes, and snippets.

@choco0908
Last active May 19, 2020 08:53
Show Gist options
  • Save choco0908/eee61ba8d78c7e601ad8ed41ca769dd7 to your computer and use it in GitHub Desktop.
Save choco0908/eee61ba8d78c7e601ad8ed41ca769dd7 to your computer and use it in GitHub Desktop.
To get world potions of geolocation using aframe-ar-nft.js (https://github.com/AR-js-org/AR.js)
function getPosition(point){
// point is geolocation, point = {latitude:'123.xx',longitude:'37.xx'}
const camera = document.querySelector('[gps-camera]').components['gps-camera'];
let position = { x: 0, y: 0, z: 0 };
// update position.x
let dstCoords = {
longitude: point.longitude,
latitude: camera.currentCoords.latitude,
};
position.x = camera.computeDistanceMeters(camera.currentCoords, dstCoords);
position.x *= point.longitude > camera.currentCoords.longitude ? 1 : -1;
// update position.z
dstCoords = {
longitude: camera.currentCoords.longitude,
latitude: point.latitude,
};
position.z = camera.computeDistanceMeters(camera.currentCoords, dstCoords);
position.z *= point.latitude > camera.currentCoords.latitude ? -1 : 1;
if (position.y !== 0) {
let altitude = camera.currentCoords.altitude !== undefined ? camera.currentCoords.altitude : 0;
position.y = position.y - altitude;
}
//return position = { x: x, y: y, z: z }
return position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment