Google地图有助于放置标记

时间:2015-09-14 17:03:16

标签: php mysql wordpress google-maps

PHP / Wordpress的新手 我已经看了一百万个地方但找不到帮助我。我试图从数据库中加载位置并在wordpress页面上显示(我制作自定义插件),然后将结果映射到谷歌地图实例上。地址已经是纬度和长度。

我可以在页面上加载并显示它,但不会在地图上放置标记。任何帮助将不胜感激。

地图实例

<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>

数据库工作

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>

1 个答案:

答案 0 :(得分:0)

我不确定AddMarker()内的initialize函数是什么引用的。

Google Maps API reference for Markers提出了两种创建标记的方法:

  1. 在初始化中使用new google.maps.Marker() 功能
  2. 在初始化函数外使用var marker = new google.maps.Marker(),然后调用marker.setMap()