2012-07-26 59 views
0

我想能够动态生成每个信息窗口的信息使用PHP的循环我创建由于某些变量的位置[我] [3]所以它​​会动态拉动信息每次通过,我可以简单地分配它。但由于某种原因,如果我尝试插入此。代码生成罚款...在源页面...但地图不会加载..有没有人有这个修复...并帮助使它的工作...多数THX在前进!信息已被动态地拉到一个单独的脚本中,$ vars只是用来从单个数组中提取信息。地图标记可以很好地与lats和lng组合在一起,它的位置数组的部分就是时髦的--ps。是的,代码中的$ vars已经被重新设置为零。但那在侧面脚本。所以它会拉出所有适当的信息。对于[3]字符串 - 地图只是不会在数组中生成。生成动态信息窗口JavaScript的Google地图

'<'script type="text/javascript"> 

    //PHP - Lat,Lng ARRAY 
    var locations = [ 

    php code <?php 
    $x = 0; $i = 0; $j = 0; 
    for($aa = 0; $aa < $count; $aa++) { 
    echo "['" . $business_name[$x] . "'," . $lat[$i] . "," . $lng[$j] . "," . "<div class='coupon'><div class='ribbon'><div class='ribbon-stitches-top'></div><strong class='ribbon-content'><h1>$deal[$y]</h1></strong><div class='ribbon-stitches-bottom'></div></div><div class='picture_coupon'><img src='$deal_photo[$b]' width='150' height='100' /></div><div class='deal'><center><h1>$deal[$y]</h1>$deal_info[$a]<b>Expires: $deal_expiration[$c]</b></center></div></div>" . "],"; 
    $x++; $i++; $j++; $id++; 
    } 
    ?> END of PHP CODE 
    [ , , , ] 
    //['Maroubra Beach', -33.950198, 151.259302, 6] 
    ]; 
    //PHP - Lat,Lng ARRAY 
     var map; 

     function initialize() { 
     var myOptions = { 
      zoom: 13, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
     map = new google.maps.Map(document.getElementById('map_canvas'), 
      myOptions); 

     // Try HTML5 geolocation 
     if(navigator.geolocation) { 
      navigator.geolocation.getCurrentPosition(function(position) { 
      var pos = new google.maps.LatLng(position.coords.latitude, 
              position.coords.longitude); 

// INVERSE CODE PHP DYNAMIC 

    var infowindow = new google.maps.InfoWindow(); 

    var marker, i; 

    var image = '../images/map-icons/blue.png'; 
    for (i = 0; i < locations.length; i++) { 
     marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
     map: map, 
     icon: image 
     }); 

     google.maps.event.addListener(marker, 'click', (function(marker, i) { 
     return function() { 
      infowindow.setContent(locations[i][3]); 
      infowindow.open(map, marker); 
     } 
     })(marker, i)); 
    } 
/* */ 
// INVERSE CODE PHP DYNAMIC 
// GEO LOCATION SET CENTER AND ERROR HANDLING 
      map.setCenter(pos); 
      }, function() { 
      handleNoGeolocation(true); 
      }); 
     } else { 
      // Browser doesn't support Geolocation 
      handleNoGeolocation(false); 
     } 
     } 

     function handleNoGeolocation(errorFlag) { 
     if (errorFlag) { 
      var content = 'Error: The Geolocation service failed.'; 
     } else { 
      var content = 'Error: Your browser doesn\'t support geolocation.'; 
     } 
// GEO LOCATION SET CENTER AND ERROR HANDLING  

     } 

    // google.maps.event.addDomListener(window, 'load', initialize); 
    </script> 

回答

0

固定 - 不幸的是回声“”;函数不允许在内部的任何东西('')来分隔div等。不幸的是,JavaScript不会加载除STANDARD html之外的任何内容。不是PHP的变体。

解决方案是用适当的html标准设置字符串,即代替并使用连接运算符。

例如:

$content = '<div class="coupon"><div class="ribbon"><div class="ribbon-stitches-top"></div><strong class="ribbon-content"><h1>'.$deal[$y].'</h1></strong><div class="ribbon-stitches-bottom"></div></div><div class="picture_coupon"><img src="'.$deal_photo[$b].'" width="150" height="100" /></div><div class="deal"><center><h1>'.$deal[$y].'</h1>'.$deal_info[$a].'<b>Expires: '.$deal_expiration[$c].'</b></center></div></div>'; 

,我分配了到数组循环看起来像这样

<?php 
$x = 0; $i = 0; $j = 0; $y = 0; $z = 0; $a = 0; $b = 0; $c = 0; 
for($aa = 0; $aa < $count; $aa++) { 
$content = '<div class="coupon"><div class="ribbon"><div class="ribbon-stitches-top"></div><strong class="ribbon-content"><h1>'.$deal[$y].'</h1></strong><div class="ribbon-stitches-bottom"></div></div><div class="picture_coupon"><img src="'.$deal_photo[$b].'" width="150" height="100" /></div><div class="deal"><center><h1>'.$deal[$y].'</h1>'.$deal_info[$a].'<b>Expires: '.$deal_expiration[$c].'</b></center></div></div>'; 

echo "['" . $business_name[$x] . "'," . $lat[$i] . "," . $lng[$j] . "," . "'$content'" . "],"; 
$x++; $i++; $j++; $id++; $y++; $z++; $a++; $b++; $c++; 
} 
?> 

我什么都不知道的JavaScript的,当涉及到什么允许goog ...所以得出这样的结论伤害了我的大脑比我甚至可以想象...