Start a new topic

how to get markers location in locationChanged

Hello,


I am trying to use a for/loop iteration to get all visible markers location in locationChanged function. I want to add in locationChanged function a system to detect if user is in the same location with the marker then marker hide. If user walk away from the marker's location then the marker should be visible again.


I think that i need something like that


for (var i = 0; i < World.markerList.length; i++) {

var location = new AR.GeoObject(World.markerList.[i].markerObject.latitude, World.markerList.[i].markerObject.longitude); <- I am confused here

if (Math.round(location.distanceToUser()) <= 5) {


marker.enabled = false;


} else {

marker.enabled = true;


}


I don't know how to set location var with each markers longitude / latitude.


Can you provide me any help? Thank you very much for your time.


Is something like that possible with alternative way? I am afraid that with my way it will cause freezes or crashes because it will use for/loop all the time.


My sdk: Javascript/android

Platform: android studio

I recommend using AR.context.onLocationChanced listener to fetch user's current location.

Assuming that you have the location of all POIs in a data structure or use the locations attribute of an AR.GeoObject, you may then just iterate through the list of markers and set "enabled" flag to something like



AR.context.onLocationChanged = function(lat, lon, alt, acc) {

  var userLocation = new AR.GeoLocation(lat, lon);

  var userDistanceMetersToHidePoi = 1000;



for (var i = 0; i < World.markerList.length; i++) {

  World.markerList[i].enabled = World.markerList[i].locations[0].distanceTo(userLocation) <= userDistanceMetersToHidePoi;

  // which is equivalent to

  World.markerList[i].enabled = World.markerList[i].locations[0].distanceToUser() <= userDistanceMetersToHidePoi;

}



  userLocation.detroy();

}



Hope this helps.


Cheers,

andi




Login or Signup to post a comment