我将此页面更改为mysqli并切换数据库。我改变的只是连接和查询。
如果我删除查询地图显示没有标记。
如果我添加查询,地图就会消失,并告诉我 initMap() 未定义。var_dump 显示查询运行良好。
我究竟做错了什么??这真的很奇怪。
提前感谢您的帮助。我最初从这里改编了代码
var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/red.png",
new google.maps.Size(32, 32), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: '<div style="color: #000">' + info + '</div>',
maxWidth: 300,
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 14,
mapTypeId: google.maps.MapTypeId.HYBRID,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.DEFAULT
}
});
<?php
$query = mysqli_query($dbc, "SELECT * FROM location");
while ($row = mysqli_fetch_array($query)){
$name=$row['name'];
$addr1=$row['address'];
$addr2=$row['address2'];
$city=$row['city'];
$state=$row['state'];
$zip=$row['zip'];
$country=$row['country'];
$lat=$row['lat'];
$lng=$row['lng'];
echo ("addMarker($lat, $lng,'<p>". $name ."</p><br/>$addr2<br/>$city, $state $zip<br />$country');\n");
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);
}
</script>
</head>
<body onLoad="initMap()" style="margin:0px; border:0px; padding:0px;">
<div class="container">
<?php
var_dump($lat, $lng, $addr2);
?>
<div class="content">
<h1 class="marked" align="left">
<div id="child" >The Big Map</div></h1><br />
<br/>
<div id="map"></div><br/>
</div>
<br/>