我不确定这是正确的群体。如果没有,请告诉我。
我的困境:
我需要从Google Maps v3 Polylines
返回的结果中将DirectionsService
添加到Google地球。网络似乎没有任何内容。它必须是可能的,因为罗马在他的驾驶模拟器中做到了这一点:http://earth-api-samples.googlecode.com/svn/trunk/demos/drive-simulator/index.html
不幸的是,他在那里使用谷歌地图v2,我似乎无法弄清楚如何将此代码转移到谷歌地图v3。
答案 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);
}
});
}