AR-js-org / AR.js

Image tracking, Location Based AR, Marker tracking. All on the Web.
MIT License
5.3k stars 909 forks source link

Allow real GPS position to be used, even after fake GPS has been set #560

Closed nickw1 closed 10 months ago

nickw1 commented 10 months ago

⚠️ All PRs have to be done versus 'dev' branch, so be aware of that, or we'll close your issue ⚠️

What kind of change does this PR introduce?

Allows real GPS position to be used even after fake GPS has been set (#500) Can it be referenced to an Issue? If so what is the issue # ?

500

How can we test it? Set up a fake GPS location in the HTML. Then use the application in a real GPS location. The real GPS location will be recognised.

Summary

Does this PR introduce a breaking change?

Please TEST your PR before proposing it. Specify here what device you have used for tests, version of OS and version of Browser

Tested by @Platform-Group, who contributed this fix (but did not prepare the PR). Verified as sensible code by @nickw1.

@kalwalt do you need to check this, or shall I just merge into dev? It's a very simple fix.

Other information

I think it would be more sensible longer-term to allow the fake GPS to be set multiple times, which this logic prevents (as did the code before this fix). However this might possibly break existing apps so needs more testing. This can be considered a 'quick fix'

kalwalt commented 10 months ago

@nickw1 i will ahve more time at the end of this month, i was very busy lately, hadn't the time to read and answer to any issue. If you think that it can be merged, go straight. 🙂

nickw1 commented 10 months ago

@kalwalt no worries, I haven't had so much time lately either! I think, to be honest, the fix is so simple that it can be merged straight away, so thanks.

kalwalt commented 10 months ago

@kalwalt no worries, I haven't had so much time lately either! I think, to be honest, the fix is so simple that it can be merged straight away, so thanks.

Ok no problems then!

Platform-Group commented 10 months ago

Hey @nickw1 there's a minor issue with this PR, because of the flag you're now not able to update the simulateLatitude or simulateLongitude values during runtime. Fixed by moving the flag check from update's if statement to play's if statement. Working code:

update: function (oldData) {
    this.threeLoc.setGpsOptions({
      gpsMinAccuracy: this.data.positionMinAccuracy,
      gpsMinDistance: this.data.gpsMinDistance,
      maximumAge: this.data.gpsTimeInterval,
    });
    if (
      (this.data.simulateLatitude !== 0 || this.data.simulateLongitude !== 0) &&
      (this.data.simulateLatitude != oldData.simulateLatitude ||
        this.data.simulateLongitude != oldData.simulateLongitude)
    ) {
      this.threeLoc.stopGps();
      this.threeLoc.fakeGps(
        this.data.simulateLongitude,
        this.data.simulateLatitude
      );
      this.data.fakeGpsStarted = true
    }
    if (this.data.simulateAltitude > -Number.MAX_VALUE) {
      this.threeLoc.setElevation(this.data.simulateAltitude + 1.6);
    }
  },

  play: function () {
    if (!this.data.fakeGpsStarted && this.data.simulateLatitude === 0 && this.data.simulateLongitude === 0) {
      this.threeLoc.startGps();
    }
  },

I'm using a button to jump the camera to different sides of a building by adjusting simulated latitude and longitude which is how I found this problem. My use case is that the devices running my program are going to be tethered to plinths in various rooms and GPS doesn't work within the building, so I needed a way to change the cameras simulated location.