【发布时间】: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