我希望能够使用由于位置[i] [3]中的某些变量而创建的php for循环动态生成每个信息窗口的信息,因此它将动态地提取每次传递的信息,我可以简单地分配它。但出于某种原因,如果我试图插入这个。代码在源页面上生成良好的...但是地图甚至不会加载..有没有人对此有一个解决方案...并帮助使其工作...很多THX在ADVANCE !!信息已在一个单独的脚本中动态提取,$ vars仅用于计数以从各个数组中提取信息。 lats和lng的地图标记很好地生成了位置数组的那个[i] [3]部分,这是时髦的 - ps。是的,代码中的$ vars再次设置为零。但那是在侧面脚本中。所以它会提取所有正确的信息。对于[3]字符串 - 地图不会在数组中生成。
'<'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 :(得分: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++;
}
?>
当谈到它允许goog的内容时,我对javascript一无所知....所以得出这个结论比我想象的还要伤害我的大脑...