Skip to content Skip to sidebar Skip to footer

Google Map Won't Display Points - XML Is Null

I'm developing a website that will read the lat and lng from the MySQL database that I've created to show them on Google Maps. I'm using this Google example as a reference. The tab

Solution 1:

var infoWindow = new google.maps.InfoWindow;

should be

var infoWindow = new google.maps.InfoWindow();

Also here you pass through 'users' (the array of objects in the 'users' node), but surely you want to pass through just 'user', i.e. the marker you've just created?

bindInfoWindow(users, map, infoWindow, html);

Solution 2:

So I figured it out. After Duncan's answer the reason which placemarks did not work was that I had not placed

header("Content-type: text/xml");

in genxml.php. What a noob, huh? I'm placing Duncan's answer as correct because without it I wouldn't have figured out the problem. Below is the updated genxml.php. Thanks!

<?php

    include("database.php");

    function parseToXML($htmlStr) 
    { 
        $xmlStr=str_replace('<','&lt;',$htmlStr); 
        $xmlStr=str_replace('>','&gt;',$xmlStr); 
        $xmlStr=str_replace('"','&quot;',$xmlStr); 
        $xmlStr=str_replace("'",'&#39;',$xmlStr); 
        $xmlStr=str_replace("&",'&amp;',$xmlStr); 
        return $xmlStr; 
    } 

    // Select all the rows in the users table
    $query = "SELECT * FROM users";
    $result = mysql_query($query);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }

    header("Content-type: text/xml"); 

    // Start XML file, echo parent node
    echo '<users>';

    // Iterate through the rows, printing XML nodes for each
    while ($row = mysql_fetch_assoc($result)){
        // ADD TO XML DOCUMENT NODE
        echo '<user ';
        echo 'name="' . parseToXML($row['name']) . '" ';
        echo 'address="' . parseToXML($row['address']) . '" ';
        echo 'lat="' . $row['lat'] . '" ';
        echo 'lng="' . $row['lng'] . '" ';
        echo '/>';
    }

    // End XML file
    echo '</users>';


?>

Post a Comment for "Google Map Won't Display Points - XML Is Null"