GOoGle Maps with Php mysql real time update

950 views
Skip to first unread message

Chathura Gunasekara

unread,
Nov 23, 2010, 8:52:43 AM11/23/10
to google-map...@googlegroups.com
Hi, Has anyone tried the article ' google maps with php mysql' and tried to update the xml file and the map,
can any one tell me how to update the map marker postions reading the updated xml file.
this is my js file.
---------------------------------------------------------------------------------------------------------------------------
    var customIcons = {
      restaurant: {
        icon:'http://labs.google.com/ridefinder/images/mm_20_red.png',
            //icon: 'http://localhost/test/tanker.jpg',
        shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
      },
      bar: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
        shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
      }
    };
   
    //var intervalID = setInterval(load, 5000);
  
   
   
   
    function load() {
       var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(6.9413,79.82),
        zoom: 14,
        mapTypeId: 'roadmap'
        });

       
      var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP file
      downloadUrl("phpsqlajax_genxml3.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var mmsi = markers[i].getAttribute("mmsi");
          var lat = markers[i].getAttribute("lat");
          var lng = markers[i].getAttribute("lng");
          var type = "bar";//markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          var html = "<b> MMSI: " + mmsi + "</b> <br/> Latitude: " + lat+"<br/> Longitude: "+lng+"<br/>";
          //alert(html);
          var icon = customIcons[type] || {};
          //var icon = customIcons[bar] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });
      //load anothor function to update data repeatedly
    setInterval(repeat,5000);



//load ends here
    }
function repeat(){
    /////////////////////////////////I added this function to update the map///////////////////////////////

    //////////////////take from xml file/////////////
    downloadUrl("phpsqlajax_genxml3.php?var=5", function(data) {
       


//////////////////problem is above php file is the same on which were there when i first loaded the page it sticks in memory and wont change so the markers are not updated. this is my problem,
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var mmsi = markers[i].getAttribute("mmsi");
          var lat = markers[i].getAttribute("lat");
          var lng = markers[i].getAttribute("lng");
          var type = "bar";//markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          var html = "<b> MMSI: " + mmsi + "</b> <br/> Latitude: " + lat+"<br/> Longitude: "+lng+"<br/>";
          //alert(html);
          var icon = customIcons[type] || {};
          //var icon = customIcons[bar] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });

   

}
    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function doNothing() {}
    //another function to


Rossko

unread,
Nov 23, 2010, 10:46:29 AM11/23/10
to Google Maps JavaScript API v3
> Hi, Has anyone tried the article ' google maps with php mysql' and
> tried to update the xml file and the map,

You seem to have ignored the advice in your previous thread today.
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/c26e50bab8f56fa7

> this is my js file.

No thanks ; if you want help, post a link to your map showing the
problem, as per posting guidelines.

Chathura Gunasekara

unread,
Nov 23, 2010, 11:31:34 AM11/23/10
to google-map...@googlegroups.com
shall i email u all the files can u put it up on a web server and check
pls snd me ur email address.

thanx

Andrew Leach

unread,
Nov 23, 2010, 11:35:47 AM11/23/10
to google-map...@googlegroups.com
On 23 November 2010 16:31, Chathura Gunasekara <chat...@gmail.com> wrote:
> shall i email u all the files can u put it up on a web server and check
> pls snd me ur email address.

Absolutely not. Please post a link to *your* installation on a web server.

This page http://groups.google.com/group/google-maps-api/web/why-including-a-link-is-critical
is still relevant to the Version 3 Group.

You would like free help. Make it easy for others to help you.

Marcela Godoy

unread,
Nov 23, 2010, 9:04:57 AM11/23/10
to google-map...@googlegroups.com
hello, try to help!
 
look in the line ->  downloadUrl("phpsqlajax_genxml3.php?var=5", function(data) {
 
what the php file?
have a variable that identifies the data?
 
why in the line after, then no statement that refers to the variable?
Marcela

2010/11/23 Chathura Gunasekara <chat...@gmail.com>


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply all
Reply to author
Forward
0 new messages