Closed marcusx2 closed 1 year ago
The distance
is not part of the component schema but a simple property of the gps-new-entity-place
component.
Use entity.components['gps-new-entity-place'].distance
.
To follow up, see this example: https://github.com/AR-js-org/AR.js/tree/master/aframe/examples/new-location-based/show-distance
Look inside clicker.js
.
You have to move to a new location after arjs started for the distance to be calculated. However this shouldn't be the case, because after starting the experience you already have the user's position and the entity's position. It's a bug, isn't it? How is the distance calculated, can you give me the formula? Thanks.
Sorry, it sounded from your original post that you were not accessing the component the correct way.
When you start the experience you might not necessarily have the position, as it might take time to obtain a new GPS position.
However on second thoughts I think you are right - if the GPS position is known already when the experience is started, you should be able to calculate the distance, but the code does not account for this yet. I'll look into it when I have a moment, apologies if I misunderstood.
... to update, the distance calculation is done in gps-new-entity-place
(https://github.com/AR-js-org/AR.js/blob/master/aframe/src/new-location-based/gps-new-entity-place.js) in the _haversineDist()
method, so if you want to fix yourself before the next release, look in there.
I still get undefined
<!DOCTYPE html>
<html>
<head>
<title>AR.js A-Frame Location-based</title>
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script type='text/javascript' src='https://raw.githack.com/AR-js-org/AR.js/master/three.js/build/ar-threex-location-only.js'></script>
<script type='text/javascript' src='https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js'></script>
</head>
<body>
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: false; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
<a-camera look-controls-enabled='false' arjs-device-orientation-controls='smoothingFactor: 0.1' gps-new-camera='positionMinAccuracy: 100; gpsMinDistance: 5; simulateLatitude: 51.049; simulateLongitude: -0.723; simulateAltitude: 0; gpsTimeInterval: 0;' position='0 10 0'></a-camera>
<a-entity material='color: red' geometry='primitive: box' gps-new-entity-place="latitude: 51.05; longitude: -0.72" scale="100 100 100" ></a-entity>
</a-scene>
<script>
const entity = document.querySelector("[gps-new-entity-place]");
console.log(entity.components['gps-new-entity-place'].distance);//returns undefined
setTimeout(() => {
console.log(entity.components['gps-new-entity-place'].distance);//returns distance
}, 0);
</script>
</body>
</html>
The PR hasn't been merged yet.
To test it you'll need to check out the distance-fix
branch and use that.
@marcusx2 I've checked the code example you gave above with the distance-fix
branch and it works, it gives a distance of around 237m.
Do you want to request a feature or report a bug?
bug
What is the current behavior?
The documentation talks about the distance property. I can't find it anywhere.
If the current behavior is a bug, please provide the steps to reproduce.
I tried
entity.getAttribute('gps-new-entity-place')
entity.getDOMAttribute('gps-new-entity-place')
entity.components['gps-new-entity-place'].data
None of them display the
distance
property, only longitude and latitude.What is the expected behavior?
To show the distance property which is the current distance from the camera. The documentation says the
gps-new-entity-place
component has this property, but I'm unable to find it.