我的代码没有在谷歌地图上显示侧边栏和标记,在输出中我只得到谷歌地图。
<?php
error_reporting(0);
include('dbcon.php');
$result = mysql_query("SELECT address FROM markers");
$new_array = array();
while ($row = mysql_fetch_assoc($result)) {
$new_array[] = $row['address'];
}
$add_js = json_encode($new_array);
//print_r($add_js);
?>
<script type="text/javascript">
var side_bar_html = "";
var gmarkers = [];
var map = null;
function initialize() {
// create the map
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(28.6139, 77.2089),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// Add markers to the map
var point = <?php echo $add_js ?>;
function geocodeAddress(i) {
geocoder.geocode({
'address' : point[i]
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
createMarker(results[0].geometry.location, i);
}
else {
alert('Geocode was not successful for the following reason: ' +
status);
}
});
return marker;
}
document.getElementById("side_bar").innerHTML = side_bar_html;
}
var infowindow = new google.maps.InfoWindow({
size: new google.maps.Size(150, 50)
});
function myclick(i) {
google.maps.event.trigger(gmarkers[i], "click");
}
function createMarker(latlng, name, html) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon : icon1,
});
//add info window
google.maps.event.addListener(marker, 'mouseover', function() {
marker.setIcon(icon2);
infowindow.setContent(point[i]);
infowindow.open(map, marker);
title: 'Property!'
});
google.maps.event.addListener(marker, 'mouseout', function() {
marker.setIcon(icon1);
infowindow.setContent(point[i]);
infowindow.close(map, marker);
title: 'Property!'
});
//end of adding info window
// save the info we need to use later for the side_bar
gmarkers.push(marker);
// add a line to the side_bar html
side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' +
name + '<\/a><br>';
}
</script>
我对这个编码概念真的很陌生,而且大部分代码都是通过谷歌搜索得到的。我已经提供了大部分代码,但我没有找到问题所在。
先感谢您。