My problem
I have the problem that the latitude and longitude is continuously randomly refreshed.
I want this to refresh only every 15 seconds. How can I fix this problem?
Why I want this
If I could get control over the refreshing moments I can use a weather api to get more details of the location.
The problem with the weather api is that I can only do 10 calls in a minute.
The code
I call a javascript function on pageload with:
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile($baseUrl.'/assets/waarnemingen/js/geo.js');
Yii::app()->clientScript->registerScript('getLocation',"document.ready(getLocation());" ,CClientScript::POS_HEAD); // is called ones on pageload.
The javascriptcode is:
function getLocation() {
if(navigator.geolocation){
// maximumAge at 60000 (1 minutes) - Get new location if the cached location is older then maximumAge
// timeout at 15000 milliseconds (15 seconds) - Timeout between new location calls
var options = {enableHighAccuracy:true, maximumAge:60000, timeout:15000};
geoLocation = navigator.geolocation;
watchID = geoLocation.watchPosition( getLocationDetails, errorHandler, options );
}else{
alert("Sorry, browser does not support geolocation!");
}
}
That calls getLocationDetails:
function getLocationDetails(position) {
// Let's fill the form with the latitude, longitude and accuracy
document.getElementById("Waarnemingen_latitude").value = position.coords.latitude.toFixed(7);
document.getElementById("Waarnemingen_longitude").value = position.coords.longitude.toFixed(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />;
document.getElementById("Waarnemingen_accuracy").value = position.coords.accuracy;
}