Javascript 谷歌地图不从mysql数据库加载点

Javascript 谷歌地图不从mysql数据库加载点,javascript,php,jquery,google-maps,google-maps-api-3,Javascript,Php,Jquery,Google Maps,Google Maps Api 3,我正在学习通过表单窗口在google地图上放置标记并将其保存到数据库的教程。一切正常,但地图加载时没有从数据库加载标记。 在包含所有html的main.php文件中,我运行了这个函数来在地图上放置标记 //############### Create Marker Function ############## function create_marker(MapPos, MapTitle, MapDesc, InfoOpenDefault, DragAble, Removable, icon

我正在学习通过表单窗口在google地图上放置标记并将其保存到数据库的教程。一切正常,但地图加载时没有从数据库加载标记。 在包含所有html的main.php文件中,我运行了这个函数来在地图上放置标记

//############### Create Marker Function ##############
function create_marker(MapPos, MapTitle, MapDesc,  InfoOpenDefault, DragAble, Removable, iconPath)
{                 

    //new marker
    var marker = new google.maps.Marker({
        position: MapPos,
        map: map,
        draggable:DragAble,
        animation: google.maps.Animation.DROP,
        title:"Hello World!",
        //icon: iconPath
    });

    //Content structure of info Window for the Markers
    var contentString = $('<div class="marker-info-win">'+
    '<div class="marker-inner-win"><span class="info-content">'+
    '<h1 class="marker-heading">'+MapTitle+'</h1>'+
    MapDesc+ 
    '</span><button name="remove-marker" class="remove-marker" title="Remove Marker">Remove Marker</button>'+
    '</div></div>');    


    //Create an infoWindow
    var infowindow = new google.maps.InfoWindow();
    //set the content of infoWindow
    infowindow.setContent(contentString[0]);

    //Find remove button in infoWindow
    var removeBtn   = contentString.find('button.remove-marker')[0];
    var saveBtn     = contentString.find('button.save-marker')[0];

    //add click listner to remove marker button
    google.maps.event.addDomListener(removeBtn, "click", function(event) {
        remove_marker(marker);
    });

    if(typeof saveBtn !== 'undefined') //continue only when save button is present
    {
        //add click listner to save marker button
        google.maps.event.addDomListener(saveBtn, "click", function(event) {
            var mReplace = contentString.find('span.info-content'); //html to be replaced after success
            var mName = contentString.find('input.save-name')[0].value; //name input field value
            var mDesc  = contentString.find('textarea.save-desc')[0].value; //description input field value
            var mType = contentString.find('select.save-type')[0].value; //type of marker

            if(mName =='' || mDesc =='')
            {
                alert("Please enter Name and Description!");
            }else{
                save_marker(marker, mName, mDesc, mType, mReplace); //call save marker function
            }
        });
    }

    //add click listner to save marker button        
    google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map,marker); // click on marker opens info window 
    });

    if(InfoOpenDefault) //whether info window should be open by default
    {
      infowindow.open(map,marker);
    }
}
在我的map_process.php文件中,处理db请求的文件。 我有这个:

<?php
//PHP 5 +

// database settings 
$db_username = 'user4321';
$db_password = '4321';
$db_name = 'test';
$db_host = 'localhost';

//mysqli
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);

if (mysqli_connect_errno()) 
{
    header('HTTP/1.1 500 Error: Could not connect to db!'); 
    exit();
}

################ Save & delete markers #################
if($_POST) //run only if there's a post data
{
    //make sure request is comming from Ajax
    $xhr = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; 
    if (!$xhr){ 
        header('HTTP/1.1 500 Error: Request must come from Ajax!'); 
        exit(); 
    }

    // get marker position and split it for database
    $mLatLang   = explode(',',$_POST["latlang"]);
    $mLat       = filter_var($mLatLang[0], FILTER_VALIDATE_FLOAT);
    $mLng       = filter_var($mLatLang[1], FILTER_VALIDATE_FLOAT);

    //Delete Marker
    if(isset($_POST["del"]) && $_POST["del"]==true)
    {
        $results = $mysqli->query("DELETE FROM markers WHERE lat=$mLat AND lng=$mLng");
        if (!$results) {  
          header('HTTP/1.1 500 Error: Could not delete Markers!'); 
          exit();
        } 
        exit("Done!");
    }

    $mName      = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
    $mAddress   = filter_var($_POST["address"], FILTER_SANITIZE_STRING);
    $mType      = filter_var($_POST["type"], FILTER_SANITIZE_STRING);

    $results = $mysqli->query("INSERT INTO markers (name, address, lat, lng, type) VALUES ('$mName','$mAddress',$mLat, $mLng, '$mType')");
    if (!$results) {  
          header('HTTP/1.1 500 Error: Could not create marker!'); 
          exit();
    } 

    $output = '<h1 class="marker-heading">'.$mName.'</h1><p>'.$mAddress.'</p>';
    exit($output);
}


################ Continue generating Map XML #################

//Create a new DOMDocument object
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers"); //Create new element node
$parnode = $dom->appendChild($node); //make the node show up 

// Select all the rows in the markers table
$results = $mysqli->query("SELECT * FROM markers WHERE 1");
if (!$results) {  
    header('HTTP/1.1 500 Error: Could not get markers!'); 
    //console.log("This an error");
    exit();
} 

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

// Iterate through the rows, adding XML nodes for each
while($obj = $results->fetch_object())
{
  $node = $dom->createElement("marker");  
  $newnode = $parnode->appendChild($node);   
  $newnode->setAttribute("name",$obj->name);
  $newnode->setAttribute("address", $obj->address);  
  $newnode->setAttribute("lat", $obj->lat);  
  $newnode->setAttribute("lng", $obj->lng);  
  $newnode->setAttribute("type", $obj->type);   
}

echo $dom->saveXML();

?>
现在,我似乎找不到为什么不首先加载标记的来源。考虑到我所有其他名称都是正确的,上面的代码是否有错误

编辑:我在控制台中收到一个500内部服务器错误,但我看不出这是问题所在,因为我有另一个正在测试的映射,它正确加载保存的点。 的格式为“GET”serveraddress/mapprocess.php 500内部服务器错误。不确定这是否有帮助,但在保存一个标记后,我成功地完成了XHR加载:get severaddress/mapprocess.php作为响应


你知道为什么这不会载入标记吗。或者确切地说我应该在哪里查找。

从标记where 1中选择*。@charlietfl去掉了where 1,仍然是相同的错误。1。页面如何加载XML?2.XML看起来像什么?3.map_process.php创建的XML有效吗?请从标题中删除逗号:Hello World!,我解决了这个问题,它与mysql和mysqli调用之间的连接混合有关。只是坚持一种类型,而且一切都很顺利。