从mySQL中连续5个位置检索谷歌地图坐标?

时间:2012-01-31 07:32:59

标签: php mysql google-maps google-maps-api-3

假设我在一行数据中有5个位置调用locationOne,locationTwo,locationThree,locationFour,locationFive。我如何调用所有这些并在下面的谷歌地图中显示?下面显示检出一个。

  var marker = new google.maps.Marker({
position: new google.maps.LatLng<?php echo $location['locationOne']; ?>,
map: map,
}); 

感谢。

2 个答案:

答案 0 :(得分:0)

0创建所有位置的数组:

var locs = [
      ['Location name 1', -33.890542, 151.274856, 4],
      ['Location name 2', -33.923036, 151.259052, 5]

    ];
  1. 显示

    for(i = 0; i&lt; locs.length; i ++){
          marker = new google.maps.Marker({         position:new google.maps.LatLng(locs [i] [1],locs [i] [2]),         地图:地图       });

答案 1 :(得分:0)

如果$ location是$ location ['locationOne'],$ location ['locationTwo']等数组,请使用以下内容:

<?php foreach($location as $location){ ?>
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(<?php echo $location; ?>),
        map: map,
    }); 
<?php } ?>