Google Maps, SQL, XML, Ajax oh my!

Quick question regarding Google Maps, AJAX and some source data.

How can I create a google map that is updated in "real time" with the information that I saved in the database?

As I see it, it works in my head.

The database collects geotagged records from users. A script (possibly php) retrieves the last entry. Javascript + AJAX takes the response and displays it on Google Maps.

How do I update and update as I enter entries?

+3
source share
1 answer

script , , , . , .

AJAX script, , timestamp .

AJAX , . AJAX timestamp.

- jQuery:

var lastUpdate = '2000/01/01 00:00:00';

function autoUpdate() {
    $.ajax({
       type: "GET",
       url: "check_updates.php?last_update=" + lastUpdate,
       dataType: 'json',
       success: function(jsonData) {

          // 1. Check if jsonData is empty. If not we received some fresh data.
          // 2. Update lastUpdate from the jsonData with the timestamp from 
          //    the server. Don't use JavaScript to update the timestamp, 
          //    because the time on the client and on the server will 
          //    never be exactly in sync.
          // 3. Move the markers on Google Map.

          // Relaunch the autoUpdate() function in 5 seconds.
          setTimeout(autoUpdate, 5000);
       }
    });
}
+3

Source: https://habr.com/ru/post/1732240/


All Articles