2011-07-14 31 views
3

哎這裏我從臨時功能的谷歌地圖谷歌地圖上畫出兩條不同的路徑與PHP

function temp(){ 
    var device_id=document.getElementById('hide').value; 
    //alert(device_id); 
    for(j=0;j<device_id;j++) 
    { 
     // alert(document.getElementById('hid'+j).value); 

     $.ajax({ 
      type: 'post', 
      url: '<?=base_url()?>index.php/admin/tracking/get_location/'+document.getElementById('hid'+j).value, 
      // data: 'season_id='+season_id, 
      dataType: "json", 
      success: function(msg) { 

       // directionsDisplay.setMap(null); 
       deleteOverlays(); 
       $.each(msg,function(index,value){ 

        var newLatlng = new google.maps.LatLng(value['lat'],value['long']); 
        map.panTo(newLatlng); 
        if(myPoints.length>0) 
        { 
         var oldLatlng=myPoints[myPoints.length-1]; 
         var myCoordinates = [ 
          oldLatlng, 
          newLatlng 
         ]; 
         var myPath = new google.maps.Polyline({ 
          path: myCoordinates, 
          strokeColor: "#FF0000", 
          strokeOpacity: 1.0, 
          strokeWeight: 2 
         }); 
         way.push(myPath); 
         myPath.setMap(map); 
        } 
        //var newLatlng = new google.maps.LatLng(value['lat'],value['long']); 
        myPoints.push(newLatlng); 
        map.panTo(newLatlng); 
       }) 
      } 
     }); 
    } 
    setTimeout("temp1()",2000); 
} 

function temp1(){ 
    var device_id=document.getElementById('hide').value; 
    //alert(device_id); 
    for(j=0;j<device_id;j++) 
    { 
     // alert(document.getElementById('hid'+j).value); 
     $.ajax({ 
      type: 'post', 
      url: '<?=base_url()?>index.php/admin/tracking/get_last_location/'+document.getElementById('hide').value, 
      // data: 'season_id='+season_id, 
      dataType: "json", 
      success: function(msg) { 
       var newLatlng = new google.maps.LatLng(msg.lat,msg.lng); 
       map.panTo(newLatlng); 
       document.getElementById('speed').value=msg.speed; 
       if(myPoints.length>0) 
       { 
        var oldLatlng=myPoints[myPoints.length-1]; 
        var myCoordinates = [ 
         oldLatlng, 
         newLatlng 
        ]; 
        if(oldLatlng!=newLatlng) 
        { 
         var myPath = new google.maps.Polyline({ 
          path: myCoordinates, 
          strokeColor: "#FF0000", 
          strokeOpacity: 1.0, 
          strokeWeight: 2 
         }); 
         way.push(myPath); 
         myPath.setMap(map); 
        } 
        myPoints.push(newLatlng); 
       } 
       else 
       { 
        //var newLatlng = new google.maps.LatLng(value['lat'],value['long']); 
        myPoints.push(newLatlng); 
       } 
      } 
     }); 
    } 
    setTimeout("temp1()",2000); 
} 

function deleteOverlays() { 
    if (myPoints.length>0) { 
     for (i in myPoints) { 
      myPoints[i].setMap(null); 
     } 
     myPoints.length = 0; 
    } 
    if (way.length>0) { 
     for (i in way) { 
      way[i].setMap(null); 
     } 
     way.length = 0; 
    } 
} 
</script> 
</head> 
    <body style="font-family: Arial; border: 0 none;"> 
    <?if (isset ($val)){$i=0; 
     foreach ($val as $d){?> 
      <input type="hidden" value="<?=$d['deviceid']?>" id="hid<?=$i?>"/> 
     <? $i++; }?> 
     <input type="hidden" value="<?=$i?>" id="hide"/> 
    <? }?> 

    <div id="map-canvas" style="width: 700px; height: 500px"></div> 
    <div> 
     <form action="<?=base_url()?>index.php/admin/tracking/index" method="post" enctype="multipart/form-data"> 
      <select name="device[]" id="device" multiple> 
      <?if (isset ($adv)){ 
       foreach ($adv as $device){?> 

       <option value="<?=$device['id']?>"><?=$device['device_name']?></option> 

      <?}}?> 
      </select> 
      <div><input type="submit" value="Check Path" name="check" /></div> 
     </form> 
    </div> 
    <div id="seediv"> 
    </div> 

    <div id="directionsPanel" style="width:700px;display: none"></div> 
    <p style="display: none">Total Distance: <span id="total"></span></p> 

    <div> 
     <label for="lname">Current Speed:</label> 
     <input type="text" name="speed" id="speed" disabled /> 
    </div> 

我開始在地圖上和temp1中的功能我得到連續點路從後根代碼數據庫。但現在我想通過選擇多組選擇選項在地圖上打印多個路徑。我怎麼能夠????

回答

0

你的問題不清楚。如果您收到N個點,則看起來您要添加N個路徑,每個點都有一個點。如果您想要一條長路徑,請將這些點添加到數組中,然後僅創建並添加多段線。如果要在地圖上繪製多個單獨的路徑,請發回一個對象數組,然後爲每個對象執行上一步。

(如果你喜歡這個答案,請接受它,並投票給我。)

達斯汀