【问题标题】:Google map API does not plot on different continents谷歌地图 API 不在不同的大陆上绘制
【发布时间】:2012-08-01 07:54:53
【问题描述】:

我已经使用谷歌地图 API 在谷歌地图上绘制了一个航点

我参考了以下页面:

https://developers.google.com/maps/documentation/javascript/directions

“在路线部分使用航点”并对其进行了一些修改,以便在地图上仅绘制 3 个点。 以下是我的 javascript 代码。

var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var initialloc = new google.maps.LatLng(12.971599, 77.594563);
    var mapOptions = {
        zoom : 6,
        mapTypeId : google.maps.MapTypeId.ROADMAP,
        center : initialloc
    }
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
    directionsDisplay.setMap(map);
    calcRoute();

}

function calcRoute() {
    var lat = new Array();
    var lon = new Array();

    var start = new google.maps.LatLng(12.971599,77.594563);
    var mid = new google.maps.LatLng(12.971558,77.594552);
    var end = new google.maps.LatLng(12.971558,77.594552);

    var waypts = [];
    waypts.push( {
        location : mid,
        stopover : true
    });


    var request = {
        origin : start,
        destination : end,
        waypoints : waypts,
        optimizeWaypoints : true,
        travelMode : google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(
                    request,
                    function(response, status) {
                        if (status == google.maps.DirectionsStatus.OK) {
                            directionsDisplay.setDirections(response);
                            var route = response.routes[0];

                        }
                    });

}

如果这 3 个地点在同一个国家/地区内,则效果很好,即它们有路线图。

我的问题是当位置位于不同大陆(例如印度和澳大利亚)时如何绘制地图?

谁能帮忙。

提前致谢。

【问题讨论】:

  • 您为什么希望能够获得从印度到澳大利亚的行车路线?
  • 如果您的目标是在两大洲之间绘制一条折线,则使用方向服务(返回“方向”)是错误的。使用 google.maps.Polyline。
  • 我需要绘制洲际和洲际。有什么办法
  • 是的,有办法。但这将取决于您的要求是什么。如果您需要行车路线,那么您将需要编写代码来使用陆地上的行车路线,以及水上/大陆之间的折线。如果您不需要行车路线(您不需要折线来跟随道路),只需使用折线。 Simple example 来自文档。
  • 行车路线返回polylines, or at least the array of coordinates needed to draw them。您可以向它们添加其他坐标。

标签: javascript html api google-maps google-maps-api-3


【解决方案1】:

问题不在于不同的大陆,而在于路由引擎的数据库是否包含关于起点和终点之间所有国家/地区的信息,包括汽车渡轮。您可以在 maps.google.com 中看到同样的情况。 Here's an intercontinental route 从欧洲到印度,但是如果您尝试将 B 标记移动到美国或加拿大,它不会获得路线,因为它不知道横跨大西洋的渡轮。 您可以在this spreadsheet 中查看覆盖哪些国家/地区。

【讨论】:

    猜你喜欢
    • 2013-05-30
    • 1970-01-01
    • 2023-04-05
    • 2017-11-18
    • 2011-12-03
    • 2013-06-23
    • 1970-01-01
    相关资源
    最近更新 更多