Yii Framework Forum: Random Renewal - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Random Renewal Inputfield value is constantly refreshed Rate Topic: -----

#1 User is offline   rjdevries 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 28-November 12

Posted 09 October 2013 - 04:01 AM

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(8);
    document.getElementById("Waarnemingen_accuracy").value   = position.coords.accuracy;
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users