Start a new topic

Context onLocationChanged Called Too Often

How do I slow down this function? It is getting called basically every second maybe more, even when my phone is sitting still...


AR.context.onLocationChanged = function(latitude, longitude, altitude, accuracy){
  //now, add custom functionality to build the AR scene based on the location
  ...
}
https://www.wikitude.com/external/doc/documentation/latest/Reference/JavaScript%20API/classes/context.html

Ok great! I was wondering if a debounce/throttle would work. Glad that is your suggestion. Thank you for the clarification on how that function is called.


What do you mean by:

"To stick to a cross-platform approach, I recommend you to implement required filters on the JS level but ensure you feed the AR-View with accurate Location information."


Do you mean the GeoLocation options such as maximum age,  timeout, and enabling high accuracy? I do not have any script on the front end that uses setLocation at this moment. That is why I was surprised that it was being called so often irregardless of if I call setLocation or not...

Hi Eric,


This callback fires every time a location updates arrives on a platform level. Depending on the underlyingLocationStrategy, it may fire periodically or only on a certain distance-delta.

You may process location updates every x seconds and ignore events fired in the meantime by implementing a "guard" on a JS level, something like 


if (Date.now() - lastLocationUpdate > 5000) {
  lastLocationUpdate = Date.now(); 
  [YOUR CODE]
}


To stick to a cross-platform approach, I recommend you to implement required filters on the JS level but ensure you feed the AR-View with accurate Location information.

Hope this helps.


Cheers,
Andreas

Login or Signup to post a comment