IRHM
IRHM

Reputation: 1326

Load Dynamic Google Markers From MySQL

I wonder whether someone could help me please.

I'm using the script below to dynamically load Google markers from a MySQL database and the script works fine.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Map My Finds - My Finds Per Location</title>
        <link rel="stylesheet" href="myfindsperlocation.css" type="text/css" media="all" />
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
        <script type="text/javascript"> 


            function load() { 
            var map = new google.maps.Map(document.getElementById("map"), { 
            center: new google.maps.LatLng(54.312195845815246,-4.45948481875007), 
            zoom:14, 
            mapTypeId: 'satellite' 
            }); 

            var infoWindow = new google.maps.InfoWindow;

            downloadUrl("loadmyfindsperlocation.php", function(data) { 
            var xml = data.responseXML; 
            var markers = xml.documentElement.getElementsByTagName("marker"); 
            var bounds = new google.maps.LatLngBounds(); 
            for (var i = 0; i < markers.length; i++) { 
            var locationid = markers[i].getAttribute("locationid"); 
            var point = new google.maps.LatLng( 
            parseFloat(markers[i].getAttribute("findosgb36lat")), 
            parseFloat(markers[i].getAttribute("findosgb36lon")));
            var marker = new google.maps.Marker({ 
            map: map, 
            position: point
            }); 
            bounds.extend(point); 
            map.fitBounds(bounds); 
            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, html);     
            }); 
            } 

            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() {} 

            </script> 
            </head> 
            <body onLoad="load()">

                            <div id="map"></div>
                        </body> 
                        </html>

You'll see it's a relatively simple form, which calls the data from an external PHP file which is shown in my script here: downloadUrl("loadmyfindsperlocation.php", function(data) {

What I'm now trying to do is incorporate the PHP script into the above, but I can't seem to get the map to load and I suspect it's something to do in calling the file as a URL.

Forgive me for asking, I'm relatively new to PHP an XML, but could someone perhaps tell me please how I could call this without loading it as an external URL.

Many thanks and kind regards

Upvotes: 1

Views: 689

Answers (1)

Tina CG Hoehr
Tina CG Hoehr

Reputation: 6779

I don't have either your CSS or PHP so I can only guess. Do you see errors in your Javascript console?

What I did was add the following styles and the map loaded, even with the PHP missing and giving me errors.

html, body, #map { margin: 0; padding: 0; height: 100% }

About loading the PHP, it has to be served to return a meaningful XML. You can have a pre-written XML and load that too.

Upvotes: 1

Related Questions