0

我不知道为什么我的谷歌标记没有显示。我正在使用 PHP 和 Java 脚本。我检查以确保$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
}
4

1 回答 1

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);
于 2012-06-14T01:10:50.703 回答