我是 Java 和 Android 新手。我需要找到两个路径点之间的最短路径。
我一整天都在寻找答案,我刚刚得到了这个代码:
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: chicago
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
function calcRoute() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
routePath = result.routes[0].overview_path;
for(var a = 0; a< routePath.length; a++){
// Your vector layer to render points with line
}
directionsDisplay.setDirections(response);
}
});
}
主要代码在这里:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
routePath = result.routes[0].overview_path;
for(var a = 0; a< routePath.length; a++){
// Your vector layer to render points with line
}
directionsDisplay.setDirections(response);
}
});
问题是我想在Android 中实现这段代码。但我不知道怎么办。
有谁知道如何更改代码以便我可以在 Android 中使用它吗?
这里是链接来源This https://gis.stackexchange.com/questions/25253/computing-shortest-distance-using-google-map-v3-and-openlayers