【问题标题】:Is there a way to create Polylines in the Google Earth API using the Google Maps v3 DirectionsService?有没有办法使用 Google Maps v3 DirectionsService 在 Google Earth API 中创建折线?
【发布时间】:2013-12-31 12:26:37
【问题描述】:

我不确定这是不是正确的组。如果没有,请告诉我。

我的困境:

我需要从 Google Maps v3 DirectionsService 返回的结果中将 Polylines 添加到 Google 地球。在这种程度上,网络上似乎没有任何内容。这必须是可能的,因为 Roman 在他的驾驶模拟器中这样做:http://earth-api-samples.googlecode.com/svn/trunk/demos/drive-simulator/index.html

不幸的是,他在那里使用的是 Google Maps v2,我似乎不知道如何将此代码传输到 Google Maps v3。

【问题讨论】:

  • 你可以回答你自己的问题!我建议将您的解决方案转换为答案(您也可以接受,但可能不会立即接受)。
  • 有 2 天的等待期来回答您自己的问题,但是是的,请按照建议在等待期结束后回答您自己的问题。

标签: google-maps-api-3 google-earth


【解决方案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);

        }
    });
}

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多