Start a new topic

how to delete "old" markers?

hello,

I'm developing an app in which users have to "check" some POIs (something similar to pokemon go). License already bought!


I'm having some trouble to delete markers once they have not to show.


I need to show the markers in a certain radius, this is accomplished, but then when user moves, the marker list has to be refreshed and remove distant pois (determined by var MIN_VIEW_DISTANCE=XXXX; )

I notticed requestDataFromLocal function is called when user moves. This adds new close POIs, but it seems it doesn't remove distant ones.

World.markerList=[]; is supposed to do that? Am I missing something?


Im useing the example app, and then modified this function:


requestDataFromLocal: function requestDataFromLocalFn(centerPointLatitude, centerPointLongitude) {

World.markerList=[];

var poiData = [];
var localData = pois; // json with all POIs
var distance=0;

var user_loc={};
user_loc.lat=centerPointLatitude;
user_loc.lng=centerPointLongitude;
 

for (var i=0;i<localData.length;i++) {
 var poi_loc={};
 poi_loc.lat=localData[i].latitude;
 poi_loc.lng=localData[i].longitude;

 distance=getDistance(user_loc,poi_loc); // returns distance


 if(distance<MIN_VIEW_DISTANCE){

 poiData.push({

 "id": localData[i].id,

 "latitude": localData[i].latitude,

 "longitude": localData[i].longitude,

 "description": "This is the description of POI#",

 "type": localData[i].type,

 "name": "POI"

 });

}
alert(poiData.length+" POIS WERE LOADED."); // This says "0" but old distant pois are still in the camera view

World.loadPoisFromJsonData(poiData);
},



Sorry I forgot to include the code for loadPoisFromJsonData function:


    loadPoisFromJsonData: function loadPoisFromJsonDataFn(poiData) {
        // empty list of visible markers
        World.markerList = [];

        World.marker = new AR.ImageResource("assets/XXXX.png");

        // loop through POI-information and create an AR.GeoObject (=Marker) per POI
        for (var currentPlaceNr = 0; currentPlaceNr < poiData.length; currentPlaceNr++) {
            var singlePoi = {
                "id": poiData[currentPlaceNr].id,
                "latitude": parseFloat(poiData[currentPlaceNr].latitude),
                "longitude": parseFloat(poiData[currentPlaceNr].longitude),
                "altitude": parseFloat(poiData[currentPlaceNr].altitude),
                "type": poiData[currentPlaceNr].type,
                "title": poiData[currentPlaceNr].name,
                "description": poiData[currentPlaceNr].description
            };
            /*
                To be able to deselect a marker while the user taps on the empty screen,
                the World object holds an array that contains each marker.
            */
            World.markerList.push(new Marker(singlePoi));
        }

        World.updateStatusMessage(currentPlaceNr + ' places loaded');
    },

Hello Joan,


Based on your description, I think that you should have a look at our sample 'Limiting Visible POIs'.


Let me know if this is not exactly what you were looking for or if still experience issues.


Thanks

Eva 

Login or Signup to post a comment