Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Maps JS v3 Mysql While循环_Javascript_Mysql_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript Google Maps JS v3 Mysql While循环

Javascript Google Maps JS v3 Mysql While循环,javascript,mysql,google-maps,google-maps-api-3,Javascript,Mysql,Google Maps,Google Maps Api 3,好的!我一直在试图弄清楚如何设置我的循环,以便能够在通过数据库中的循环生成的谷歌地图内的信息窗口中具有可点击的PIN。我可以让它显示所有的PIN,但是一旦我添加了可点击的PIN,它就会停止 注: 如果我只有一个针,它就可以了。 我对Javascript知之甚少,所以它可能很简单 <script type="text/javascript"> function init_map() {var myOptions = {zo

好的!我一直在试图弄清楚如何设置我的循环,以便能够在通过数据库中的循环生成的谷歌地图内的信息窗口中具有可点击的PIN。我可以让它显示所有的PIN,但是一旦我添加了可点击的PIN,它就会停止

注:

如果我只有一个针,它就可以了。 我对Javascript知之甚少,所以它可能很简单

        <script type="text/javascript"> function init_map()
                        {var myOptions = {zoom:14,center:new google.maps.LatLng(44.4765519,-73.21252950000002),mapTypeId: google.maps.MapTypeId.ROADMAP};

                map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
                <?php
                if (mysqli_num_rows($result) > 0)
                {
                  while($row = $result->fetch_assoc())
                  {
                ?>

                        marker = new google.maps.Marker(
                            {map: map,position: new google.maps.LatLng(<?php echo $row["fldLatLong"] ?>)}
                            );
google.maps.event.addListener(marker, "click", function(){infowindow.open(map,marker);});
                  <?php }}; ?>

                        </script>
函数初始化映射()
{var myOptions={zoom:14,中间:new google.maps.LatLng(44.4765519,-73.21252950000002),mapTypeId:google.maps.mapTypeId.ROADMAP};
map=new google.maps.map(document.getElementById(“gmap_画布”),myOptions);
marker=新的google.maps.marker(
{map:map,position:new google.maps.LatLng()}
);
google.maps.event.addListener(marker,“click”,function(){infowindow.open(map,marker);});

您想做的事情可能更像这样

<?php
$mysqli = new mysqli('localhost', 'root', '', 'stackoverflow'); // use your own settings
$result = $mysqli->query("SELECT fldLatLong FROM city");
$loc = array();
if (mysqli_num_rows($result) > 0) {
  while($row = $result->fetch_assoc()) {
    $loc[] = explode(',', $row["fldLatLong"]);  //  it's even better if you have a separate lat and lng in the database
  }
  // make the array javascript-readable
  $locations = 'var locations = ' . json_encode($loc) . ';';
}
?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript"> 
<?php echo $locations; ?>  // array of the locations
var markers = [];   // marker objects in an array
function init_map() {
  var myOptions = {
    zoom: 12,
    center: new google.maps.LatLng(50.8625502000,4.3796600000),  // (44.4765519,-73.21252950000002),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
  var infowindow = new google.maps.InfoWindow({
    content: 'Hello World!'
  });
  for(var i=0; i<locations.length; i++) {
    marker = new google.maps.Marker({
      map: map,
      position: new google.maps.LatLng(locations[i][0], locations[i][1])
    });
    // store the marker in the array
    markers.push(marker);
    google.maps.event.addListener(marker, "click", function() {
      // the marker tha has been clicked upon, is "this".
      // we search in the array of markers objects to see which marker was clicked upon
      var index = markers.indexOf(this);  
      var content = 'Dummy content of marker ' + index;
      infowindow.setContent(content);
      infowindow.open(map, markers[index]);
    });
  }
}
google.maps.event.addDomListener(window, 'load', init_map);
</script>
<style>
#gmap_canvas {
  height: 500px;
}
</style>
<div id="gmap_canvas"></div>

不,不是这样做的。函数不是这样使用的。您编写函数并向其提供数据;您不会每次数据更改时都更改函数。因此,函数中没有php while循环