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
Hello,
i use the following OnLocationCahnged function, but it has no effect on the marker.
Any suggestions?
/* Location updates, fired every time you call architectView.setLocation() in native environment. */
locationChanged: function locationChangedFn(lat, lon, alt, acc) {
/* Request data if not already present. */
var userLocation = new AR.GeoLocation(lat, lon);
var userDistanceMetersToHidePoi = 1000;
if (!World.initiallyLoadedData) {
World.requestDataFromLocal(lat, lon);
World.initiallyLoadedData = true;
} else if (World.locationUpdateCounter === 0) {
/*
Update placemark distance information frequently, you max also update distances only every 10m with
some more effort.
*/
World.updateDistanceToUserValues();
}
/* Helper used to update placemark information every now and then (e.g. every 10 location upadtes fired). */
World.locationUpdateCounter =
(++World.locationUpdateCounter % World.updatePlacemarkDistancesEveryXLocationUpdates);
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
}
userLocation.detroy();
},
Hi,
Could you please provide further details:
Thx and greetings
Nicola
Emmanouil Tsikniadopoulos
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.