使用php / mysql和谷歌地图 - 不显示标记

时间:2014-11-02 09:06:53

标签: php mysql google-maps

我在过去一周检查了所有类似的科目,但问题仍然无法解决。有人可以帮助我的地图不显示标记吗?

作为Using PHP/MySQL with Google Maps,我一步一步地遵循:

  1. 创建表格
  2. 填充表格
  3. 使用PHP输出XML(使用PHP的DOM函数输出XML(PHP5))
  4. 创建地图
  5. 关于第3项(使用PHP输出XML),我得到了:

    一个。 phpsqlajax_dbinfo.php(从谷歌地图api复制)

    <?php
    $username="root";
    $password="***********";
    $database="maps";
    ?>
    

    B中。 phpsqlajax_genxml3.php(从谷歌地图api复制)

    <?php
    require("phpsqlajax_dbinfo.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; 
    } 
    
    // Opens a connection to a MySQL server
    $connection=mysql_connect (localhost, $username, $password);
    if (!$connection) {
      die('Not connected : ' . mysql_error());
    }
    
    // Set the active MySQL database
    $db_selected = mysql_select_db($database, $connection);
    if (!$db_selected) {
      die ('Can\'t use db : ' . mysql_error());
    }
    
    // Select all the rows in the markers table
    $query = "SELECT * FROM markers WHERE 1";
    $result = mysql_query($query);
    if (!$result) {
      die('Invalid query: ' . mysql_error());
    }
    
    header("Content-type: text/xml");
    
    // Start XML file, echo parent node
    echo '<markers>';
    
    // Iterate through the rows, printing XML nodes for each
    while ($row = @mysql_fetch_assoc($result)){
      // ADD TO XML DOCUMENT NODE
      echo '<marker ';
      echo 'name="' . parseToXML($row['name']) . '" ';
      echo 'address="' . parseToXML($row['address']) . '" ';
      echo 'lat="' . $row['lat'] . '" ';
      echo 'lng="' . $row['lng'] . '" ';
      echo 'type="' . $row['type'] . '" ';
      echo '/>';
    }
    
    // End XML file
    echo '</markers>';
    
    ?>
    

    关于第4项(创建地图),我得到了:

    ℃。 phpsqlajax_map_v3.html(从谷歌地图api复制)

    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Google Maps AJAX + mySQL/PHP Example</title>
        <script src="http://maps.google.com/maps/api/js?sensor=false"
                type="text/javascript"></script>
        <script type="text/javascript">
        //<![CDATA[
    
        var customIcons = {
          restaurant: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
          },
          bar: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
          }
        };
    
        function load() {
          var map = new google.maps.Map(document.getElementById("map"), {
    
            center: new google.maps.LatLng(47.6145, -122.3418),
            zoom: 13,
            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 name = markers[i].getAttribute("name");
              var address = markers[i].getAttribute("address");
              var type = markers[i].getAttribute("type");
              var point = new google.maps.LatLng(
                  parseFloat(markers[i].getAttribute("lat")),
                  parseFloat(markers[i].getAttribute("lng")));
              var html = "<b>" + name + "</b> <br/>" + address;
              var icon = customIcons[type] || {};
              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() {}
    
        //]]>
      </script>
      </head>
    
      <body onload="load()">
        <div id="map" style="width: 500px; height: 300px"></div>
      </body>
    </html>
    

    要运行html文件,只有没有标记的地图。请提前帮助并表示感谢。

0 个答案:

没有答案