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 に答える