1

I'm using ar.js/a-farme to put GPS entities My problem is that the position of the entities is not accurate and it is moving with me (not stable). even that the distance between them is 1346m it looks like they are so close. And I make a pipe link between two GPS entities so due to the bad position the pipe looks so small that it should be. how it looks on my mobile browser

this is my code to create the egps entity:

private createEntity(element: any): any {
    const gpsEntity: any = document.createElement('a-entity');
    gpsEntity.setAttribute('id', element.id);
    gpsEntity.setAttribute('gps-entity-place', 'latitude:' + element.Latitude + '; longitude:' + element.Longitude);
    return gpsEntity;
  }
M -
  • 26,908
  • 11
  • 49
  • 81
s bs
  • 13
  • 4

2 Answers2

2

This might be because of inaccurate gps data (your lat/long). simply, if your lat/long data doesn't get updated, the gps-entity moves with your camera ( because AR.js doesn't understand that you have moved to set your new location in 3D World ) If you have more questions on this, please don't hesitate to ask!

  • thx for your answer, do you have any good example to follow about updating the position? – s bs May 16 '22 at 16:42
  • for debuging purpose, you can simply use javascript's "gpsWatchLocation API" to see how often your gps data gets updated ( keep in mind that every gps position update, updates your position in AR.JS 3D world ) But the main question is how to fix this problem even when gps is inaccurate ? well, this is not easy! you should use complex cv algorithms such as "SLAM" or "Visual Odometry" to obtain your location in 3D world (even when gps signal is lost). Thats what famous libraries (ARCore/ARKit) do actually but it isn't in AR.js until now. so you should implement that yourself. – amirhossein.razlighi May 17 '22 at 11:41
  • I changed my device to one that have an accurate gps, i used navigator.geolocation.watchPosition(updatePosition) to get my position updated, i get the distance and the bearing with geodesy/latlon-ellipsoidal-vincenty.js library but still can't figure out how to use this infos to put my entities in ar.js 3D world – s bs May 20 '22 at 16:13
  • well, if your location data (gps) is accurate, please check [this sample](https://github.com/nicolocarpignoli/location-based-ar-tutorial/tree/master/static-places) (with your latitude and longtitude) and tell if you can see 3D models floating in the air! try getting close to them and see if you can (if your gps data is inaccurate, the 3D models move as you move your camera and don't stay still !) please consider that if you're indoor, your gps data is absolutely inaccurate! – amirhossein.razlighi May 21 '22 at 10:00
  • after several attempts the result is not what i expected, i am using samsung s8 it gives me right (lalt/long) with compass but with the static exemple the pokemon is not fixed, it's not moving with camera (right left up down) but moving with me in the same direction its always in front of me :/ – s bs May 23 '22 at 14:36
  • I think I know what your problem is! are you using any 'look-control' component in your ar.js code? it allows your website to get 'Device Orientation' Controlls. If you don't have Device Orientation Control, you won't be able to feel the movement of your device with respect to augmented object! – amirhossein.razlighi May 24 '22 at 05:50
  • A sample (in aframe + ar.js) to understand my solution better: ` ` – amirhossein.razlighi May 24 '22 at 05:51
  • still the same as long as the camera is toward the pokemon, it's moving with me, its not fix at one point – s bs May 24 '22 at 08:21
  • do you give the 'Device orientation Access' to the website ?! This means that on beginnig of your AR experience , you should be asked for 2 accesses; 1- Camera Access 2- Device Orientation Access – amirhossein.razlighi May 24 '22 at 11:48
  • it asks for position and camera, but the device detect the orientation when i log, are you saying that if my device is accurate so i don't need to add anything or any calculation and lat/long is enough to show 3d elements in their correct place ? cause i m not really understanding the problem in my example – s bs May 24 '22 at 15:12
2

Check this sample (with your desired lat/long) to make sure your device orientation is okay:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>Location-based AR.js demo</title>
    <script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
    <script src="https://unpkg.com/aframe-look-at-component@0.8.0/dist/aframe-look-at-component.min.js"></script>
    <script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
  </head>

  <body style="margin: 0; overflow: hidden;">
    <a-scene
      vr-mode-ui="enabled: false"
      embedded
      arjs="sourceType: webcam; debugUIEnabled: false;"
    >
      <a-text
        value="This content will always face you."
        look-at="[gps-camera]"
        scale="50 50 50"
        gps-entity-place="latitude: <add-your-latitude>; longitude: <add-your-longitude>;"
      ></a-text>
      <a-camera gps-camera rotation-reader> </a-camera>
    </a-scene>
  </body>
</html>

if you can see the text "This Content always face you" and while you rotate your device , it stays in it place , it means that your GPS + Device Orientation works fine . otherwise there is a problem with your gps (inaccurate gps) or your devie orientation ( website doesn't have access to it). please let me know!

  • Hello, the text is facing me and when i rotate it satys in it place as u said – s bs May 25 '22 at 10:28
  • alright. so the problem in your code maybe is from your gps-camera or 'rotation-reader' component( add it to tour gps-camera) and after that, you are good to go! – amirhossein.razlighi May 25 '22 at 10:43
  • 1
    after testing my own example again & again you'r right it works fine, the problem shows when i change the y of position (-90) to make it look like it is on the ground – s bs May 25 '22 at 14:09
  • glad I could help :) It will be nice of you if you vote my answers – amirhossein.razlighi May 27 '22 at 11:13