我不知道为什么我的谷歌标记没有显示。我正在使用PHP和Java Script。我检查过以确保$DNB
中包含元素。这是我的代码:
while($DNB -> fetch())
{
?>
var point = new GLatLng(<?php echo intval($lat) ?>, <?php echo intval($lon) ?>);
var marker = new google.maps.Marker({position: point, map:map});
<?php
}
答案 0 :(得分:1)
根据您提供的代码,虽然您的$DNB
可能包含内容,但看起来您的$ lat和$ lon未初始化。
如果这不能解决您的问题,请参阅我在下面的工作示例:
function initialize() {
var myOptions = {
zoom: 10,
center: new google.maps.LatLng(0, 0),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(
document.getElementById("map_canvas"),myOptions);
setMarkers(map, beaches);
}
var beaches = [
['SANTA MONICA HEALTHCARE CENTER',34.0295,-118.481],
['BRENTWOOD NURSING & REHAB',34.0389,-118.47],
['FIRESIDE CONVALESCENT HOSPITAL',34.0218,-118.503],
['ARBOR VIEW REHAB AN WELLNESS CENTER',34.0291,-118.481],
['SEAPORT 17TH CARE CENTER',34.0272,-118.484],
['GOLDSTAR HEALTHCARE CTR SANTA MONICA',34.0256,-118.486],
['PACIFIC CONVALESCENT CENTER',34.0273,-118.484],
['GOOD SHEPHERD HEALTH CARE CENTER',34.0234,-118.49],
['BERKLEY WEST CONVALESCENT HOSPITAL',34.0272,-118.485],
['SANTA MONICA CONVALESCENT CENTER II',34.0241,-118.459],
['BERKLEY EAST CONVALESCENT HOSPITAL',34.0302,-118.481],
['SANTA MONICA CONVALESCENT CENTER I',34.0241,-118.459]
];
function setMarkers(map, locations) {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: beach[0],
zIndex: beach[3]
});
bounds.extend(myLatLng);
map.fitBounds(bounds);
}
}
google.maps.event.addDomListener(window, 'load', initialize);