生成动态信息窗口phpJavascript谷歌地图


generating dynamic info windows php Javascript Googlemaps

我希望能够使用php for循环为每个信息窗口动态生成信息,因为我在位置[I][3]中创建了某些变量,所以它会在每次传递时动态提取信息,我可以简单地分配它。但出于某种原因,如果我试图插入它。代码生成精细。。。在源页面上。。。但地图甚至无法加载。。有人能解决这个问题吗。。。并帮助它发挥作用。。。大量THX提前!!信息是在一个单独的脚本中动态提取的,$vars只是用于从单个数组中提取信息的计数。地图标记与lats和lng一起生成得很好。它是位置数组的[i][3]部分,这很时髦。是的,代码中的$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>

固定-不幸的是,echo";函数不允许除了内部的('')之外的任何东西来分隔div等。不幸的是,javascript内部除了STANDARD html之外不会加载任何东西。这不是PHP的变体。

解决方案是使用适当的html标准ie设置字符串,而不是使用串联运算符。

例如:

$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允许谷歌做什么时,我对它一无所知。。。。所以得出这个结论比我想象的更伤脑筋。。。