2015-09-14 120 views
0

很新的PHP/Wordpress 我看了一百萬個地方,但發現很少幫助我。我試圖從數據庫中加載位置並顯示在wordpress頁面上(自定義插件正在製作),然後將結果映射到Google地圖實例。地址已經很長。谷歌地圖幫助放置標記

我可以加載並顯示在頁面上,但不會在地圖上放置標記。任何幫助,將不勝感激。

地圖實例

<script> 
function initialize($Item) 
{ 
var mapProp = { 
    center:new google.maps.LatLng(53.548099, -113.522532), 
    zoom:18, 
    mapTypeId:google.maps.MapTypeId.SATELLITE 
    }; 
var map=new google.maps.Map(document.getElementById("map") 
    ,mapProp); 
echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n"); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 
</script> 

DB工作

if(isset($_POST['SubmitButton'])){ //check if form was submitted 

// Set variables 
$data = array(); 
$input = $_POST['text']; //get input text 
$table = $_POST['field']; //get Table 
$org = $_POST['org']; 

// Check if input is empty 

if(!empty($input)){ 

// Debug line comment out 
// echo "<script type='text/javascript'>alert('You Entered: ".$input." from ".$table." looking for ".$org."');</script>"; 

global $wpdb; 

// Check if Organization set to all or something else 
if ($_POST['org'] == "All") { 

$feed = $wpdb->get_results("SELECT * from wp_NBDonation where $table  like '%{$input}%' order by Type;"); 
} else { 

$feed = $wpdb->get_results("SELECT * from wp_NBDonation where $table  like '%{$input}%' and Type in('$org','Both');"); 
} 

echo "<ul id='list'>"; 
// if 0 results display message 
    if($feed==null){ 
     echo "<script type='text/javascript'>alert('No results found.');</script>"; 
    }else{ 

if(is_array($feed) && count($feed) > 0) { 
foreach($feed as $item){ 
    $data[] = $feed; 
    echo "<li id='item'>"; 
    echo "<h2>".$item->Type."<br>"; 
    echo $item->Name."</h2>"; 
    echo "<hr>"; 
    echo "<span id='head'>Address:</span><br>"; 
    echo $item->Address."<br>"; 
    echo $item->City." ".$item->State_Province."<br>"; 
    echo $item->Postalcode."<br>"; 
    echo "<br>"; 
    echo "<span id='head'>Phone:</span> ".$item->ContactNumber." <br>"; 
    echo "<span id='head'>Email: </span> <a href='mailto:".$item->Email."?Subject=Donation Inquiry'>".$item->Email." </a><br>"; 
    echo "<span id='head'>Website: </span> <a href='http://".$item->Website."'target=_blank>".$item->Website."</a><br>"; 
    echo "<br>"; 
    echo "<span id='head'>Instructions:</span><br>"; 
    echo $item->ContactInstructions."<br><br>"; 
    echo "<span id='head'>Payment Method: </span><br>"; 
    echo $item->PaymentMethod."<br>"; 
    echo "</li>"; // closes Item 
    $lat=$Item->lat; 
    $lon=$Item->lng; 
    $name=$Item->Name; 
    $desc=$Item->Type; 

} // end ForEach 
} // end if array 
} // end if null 
echo "<script type='text/javascript'>alert(print_r($data));</script>"; 

?> 
<div id='map'></div> 
+0

到底是什麼問題?你只說了你想做的事情。 – csmckelvey

+0

對不起,我可以加載並顯示在頁面上,但不會在地圖上放置標記。 – Jeremy

回答

0

我不知道是什麼AddMarker()功能的的initialize內部參考。

Google Maps API reference for Markers提出兩種方法來創建標記:

  1. 使用new google.maps.Marker()使用var marker = new google.maps.Marker()您的初始化函數以外的初始化 功能
  2. 內,然後調用marker.setMap()