0

我需要使用 PHP codeigniter 显示数据库中的标记我不会得到地图

function initialize() {
    var myLatLng = new google.maps.LatLng(18.5236, 73.8478);
    var mapOptions = {
        zoom: 14,
        center: myLatLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

    // Add 5 markers to the map at random locations.
    var southWest = new google.maps.LatLng(18.5236,73.8478);
    var northEast = new google.maps.LatLng(19.5236,75.8478);

    var bounds = new google.maps.LatLngBounds(southWest,northEast);
    map.fitBounds(bounds);
    var lngSpan = northEast.lng() - southWest.lng();
    var latSpan = northEast.lat() - southWest.lat();


//If I comment below line it show blank map

    beaches =  [ <?php foreach($records as $row) echo "[".$row->property_title.', '.$row->property_latitude.', '.$row->property_longitude.'],'?>]"

    for (var i = 0; i < beaches.length; i++) {
          var beach = beaches[i];
          var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
          var marker = new google.maps.Marker({
              position: myLatLng,
              map: map,
              title: beach[0]            
          });           
      }                                           
}
4

2 回答 2

2

如果$row->property_title是字符串,则需要在引号之间:

echo "['".$row->property_title."', ".$row->property_latitude.', '.$row->property_longitude.'],'?>]"

或者,您可以使用json_encode输出您的数组:

<?php
$beaches = array();
foreach ($records as $row) {$beaches[] = array($row->property_title, $row->property_latitude, $row->property_longitude);}
echo 'beaches = ' . json_encode($beaches) . ';';
?>
于 2013-02-08T10:56:25.020 回答
0
    $beaches = "['".$row->property_title."', '".$row->property_latitude."', '".$row->property_longitude."']";

var beaches=[<?php echo $beaches;?>];
于 2013-02-08T10:55:26.657 回答