function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gauri Kasat 8Gauri Kasat 8 

i need to take location after specific interval of time till the end time

Hello..

My requirement is to take location from user say after every 1 hours and the end time is 2 hours.
how to do this?
    

  var initDate = new Date(); // Or get the user login date from an HTML element (i.e. hidden input)
                    var interval;
                    
                    interval = window.setInterval(function() {
                        var now = new Date();
                  
                        if(hours=='' || hours==null || hours ==undefined){
                            getLocations();
                        }else{
                            if(now.getTime() - initDate.getTime() < hours*60*60*1000 && now.getDate() == initDate.getDate()) {
                               
                                getLocations();
                            }
                            else {
                                stopJourney();
                                window.clearInterval(interval);
                                toggleAdjustment();
                                checkInToggle();
                                toggleAdjustment();
                                var element1 = document.getElementById("stopInactive");
                                element1.classList.toggle("clsHide");
                                var element2 = document.getElementById("stop");
                                element2.classList.toggle("clsHide");
                                
                            }
                        }
                    }, intervalInMinutes*60*60*1000);
                });


Note: value of "hours" varaible : 2
value of "intervalInMinutes" : 1
 
Ajvad AjuAjvad Aju
Hi Gauri,
You will get location of user with the below code in your visualforce page.
You can schedule this feature with Schedulable interface in salesforce, Through that you can call this method or you can specify in which time and the mehod will work when that time comes.
 
<apex:page>
<h1>Welcome </h1> Your Location is
	
    <div><h3>Latitude</h3>
    </div>  
   
    <div id="startLat">
      </div>
    
    <div><h3>Longitude</h3>
    </div>  
	<div id="startLon">
	</div>

<script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('startLat').innerHTML = startPos.coords.latitude;
            document.getElementById('startLon').innerHTML = startPos.coords.longitude;
        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
</script>
</apex:page>

Regards
Ajvad Aju