2013-03-09 17 views
0

我有一个SQL查询,我将结果与mysql_fetch_array传入while循环,并且我正在打印一张表。我认为,每行中包含的信息都是在地图上构建的。 当我构建地图时,问题在于地图总是居中在表格的最后一行(C标记)。而不是我想要的地图中心到标记A(表的第一行)。 我正在寻找扭转阵列,但不起作用。打印标记与v2 API与表信息的顺序不同

<?php 
    while($info4 = mysql_fetch_array($result4)) 
    {  

    ?> 


     // A function to create the marker and set up the event window 
     function createMarker(point, name, html, flag) 
     { 
     //set the icon of the marker   
     var letteredIcon = new GIcon(baseIcon); 
     letteredIcon.image = "markers/"+flag+".png"; 

     // Set up our GMarkerOptions object 
     markerOptions = { icon:letteredIcon }; 
     var marker = new GMarker(point, markerOptions); 
     GEvent.addListener(marker, "click", function() { 
      marker.openInfoWindowHtml(html); 
     }); 
     // save the info we need to use later for the side_bar 
     gmarkers.push(marker); 
     // add a line to the side_bar html 
     side_bar_html += '<td><a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><\/td>'; 
     return marker; 
     } 


     // add the points 
     map.setCenter(new GLatLng(<?php print $info4['placeY'];?>,<?php print $info4['placeX'];?>), 14);  
     var point = new GLatLng(<?php print $info4['placeY'];?>,<?php print $info4['placeX'];?>); 
     var marker = createMarker(point,"<?php print utf8_decode($info4['placeName']);?>","<?php print utf8_decode($info4['placeName'])."<br>".utf8_decode($info4['placeAddress'])."<br>".utf8_decode($info4['placeDistrict']);?>","<?=$flag;?>") 
     map.addOverlay(marker); 

    <?php $flag=$flag+1; 
    } ?> 

一个例子: 表:

甲观光剧场

潮汐

的乙观光现象

Ç观光红屋

在这个例子中地图以C标记为中心,而不是我想要看到的A标记。

+0

你都知道,[谷歌地图API V2](https://developers.google.com/maps/documentation/javascript/v2/reference)已被正式弃用2010年5月19日? V2 API将继续工作到2013年5月19日。该API的新发展不鼓励。 – geocodezip 2013-03-09 16:14:08

回答

0

所以,而不是使用while循环,正确的代码如下。

//make an array 
    $rows = array(); 
while ($row=mysql_fetch_array($result4)){ 
//push the rows to the empty array 
    array_push($rows, $row); 
} 
// reverse the order of the rows 
$reversedarray=array_reverse($rows); 
    //use the info of each row as the variable $info4 
foreach ($reversedarray as $info4) { 
    //the code