GPS Tracking from Mysql Database

1272
1
06-06-2014 05:16 PM
HectorChapa
Occasional Contributor II
I am trying to write a javascript application that puts points based on gps coordinates that are stored in mysql database. The database is been populate by an application on a android device and its getting its coordinates and sending them to mysql database. I want to plot the gps that are stored in that database so I can see in real life time where that person is going. I am trying to use ajax in this approach but the problem I am encountering is that I am trying to write a function that I can set an interval.
For example,

function NameOfFunction()     This function is requesting the last record of that mysql database. stores in div html tag as hidden
value
{
dojo.xhrGet({
  
    url: "get-gps.php",
   
    load: function(result) {
       document.getElementById("lng").innerHTML = result;
    }
});
  
}

window.setInterval("NameOfFunction()", 1000);

The problem is how I write a function inside
dojo that can do interval timer so I can track does gps coordinates.
Does anyone have any suggestions or a better approach to my problem.....


Any Ideas........

Please help!!!!
0 Kudos
1 Reply
LixianDai
New Contributor II
$(document).ready(function () {
                    function refreshInterval() {

                        $.ajax({
                            url: YourAppConfig.yourPHPUrl,
                            cache: false,
                            dataType: 'json',
                            success: function (data) {
                                Your js function to deal with your gpsdata (data);

                                //Update the date label every 30 seconds
                                var currentdate = new Date();
                                var datetime = "Last update: " + currentdate.getDate() + "/"
                                                + (currentdate.getMonth() + 1) + "/"
                                                + currentdate.getFullYear() + " "
                                                + currentdate.getHours() + ":"
                                                + currentdate.getMinutes() + ":"
                                                + currentdate.getSeconds();

                                var lblupdateTime = document.getElementById("lblLastupdateTime");
                                if (lblupdateTime)
                                    lblupdateTime.innerHTML = datetime;
                            }
                        });
                    }

                    var refreshIntervalPara = setInterval(refreshInterval, 30 * 1000);
                    refreshInterval();
                  
                });
0 Kudos