0

我希望能够使用由于位置 [i] [3] 中的某些变量而创建的 php for 循环为每个信息窗口动态生成信息,因此它将在每次传递时动态提取信息,我可以简单地分配它。但由于某种原因,如果我尝试插入它。代码生成良好......在源页面上......但地图甚至不会加载......有没有人对此有修复......并帮助使其工作......提前多谢!信息已在单独的脚本中动态提取 $vars 仅用于计数以从各个数组中提取信息。地图标记与 lats 和 lng 一起生成很好,它是位置数组的 [i][3] 部分,这很时髦,而且 -- ps。是的,代码中的 $vars 已再次设置为零。但那是在侧面脚本中。所以它确实提取了所有正确的信息。

'<'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>
4

1 回答 1

0

已修复——不幸的是回声“”;函数不允许除 ('') 之外的任何内容来分隔 div 等。不幸的是,javascript 不会加载除标准 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....所以得出这个结论对我的大脑的伤害超出了我的想象...

于 2012-07-26T20:38:06.827 回答