I'm primarily an Electrical hardware engineer with a very little knowledge in php, javascript and similar languages.
I'm building a system that will track my device in a real time and visually display current GPS position of it on a Google map. My device is able to properly send data about its position (latitude and longitude) as often as I want. GPS position data is sent using a HTTP communication protocol (GET requests) and is stored on a server side in a .txt file called gps.txt.
php script extracts data from that gps.txt file and displays them on a Google map.
Here is the script written in php (I applied my own API key for properly use Google maps).
This script runs on some free web hosting platform. Take a look here.
Now, the trouble comes when I call the script from my web browser. Namely, although a gps.txt data is properly refreshed with a fresh data, these new position markers are NOT displayed on the map. It seems that either my web browser or my web server are cashing some data and don't allow the script to run over a fresh gps.txt file.
I suppose that, for many of you web software guys out there, this is a trivial problem.
I also tried to prevent data cashing on my browser by including
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
in my script but with NO success.
Would you, please, give me any suggestion on how to overcome this situation and always have the latest GPS position displayed on my map?
Thank you very much for your time and effort to help me.
Sincerely,
Bojan
This disables the cache for all jQuery requests:
$.ajaxSetup ({
// Disable caching of AJAX responses
cache: false
});
You can paste that into you initialize
function and see if it works!
Another handcrafted solution would be adding an increasing number to the file URL each time you fetch the text file, for example gps.txt?1
, then gps.txt?2
, and so on: as far as the browser knows there a different URL so they (kind of) get cached separately.