2012-05-07 26 views
1

我不確定這是否合適。如果沒有,請讓我知道。有沒有辦法使用Google Maps v3 DirectionsService在Google Earth API中創建多義線?

我的困境:

我需要從結果我回來從谷歌地圖添加Polylines到谷歌地球V3 DirectionsService。在這種程度上,網絡上似乎沒有任何東西。它是可能的,因爲羅馬的確可以在他自己的駕駛模擬器:http://earth-api-samples.googlecode.com/svn/trunk/demos/drive-simulator/index.html

不幸的是,他使用谷歌地圖v2的那裏,我似乎無法弄清楚如何將此代碼轉移到谷歌地圖V3。

+1

你可以回答你自己的問題!我建議將您的解決方案轉換爲答案(您也可以接受,但可能不會立即)。 –

+0

有兩天的等待期來回答你自己的問題,但是,請等待期限過後,請遵循建議並回答你自己的問題。 –

回答

1

如果有人有興趣,這裏是我如何設法解決它:

function DrawLinesOnEarth() { 
    var sLat; 
    var sLon; 
    //var start = document.getElementById("start").value; 
    //var end = document.getElementById("end").value; 
    var request = { 
     origin: '40.306134,-74.05018', 
     destination: '40.313223,-74.043496', 
     travelMode: google.maps.TravelMode.WALKING 
    }; 
    directionsService.route(request, function (result, status) { 
     if (status == google.maps.DirectionsStatus.OK) { 
      directionsDisplay.setDirections(result); 
      var steps = result.routes[0].legs[0].steps; 

      //Step through array of step legs and create polylines one by one 
      var lineStringPlacemark = IMC_ge.createPlacemark(''); 
      var lineString = IMC_ge.createLineString(''); 
      lineStringPlacemark.setGeometry(lineString); 
      // Add LineString points 
      for (var x in steps) { 
       for (var y in steps[x].path) { 
        sLat = steps[x].path[y].Na; 
        sLon = steps[x].path[y].Oa; 
        lineString.getCoordinates().pushLatLngAlt(sLat, sLon, 0); 
       } 
      } 
      // Add the feature to Earth 
      IMC_ge.getFeatures().appendChild(lineStringPlacemark); 

     } 
    }); 
} 
相關問題