我是 Java 和 Android 的新手。我需要找到两个 goepoint 之间的最短路径。我整天都在寻找答案,我刚刚得到了这个代码:
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 中使用它?
这里是链接源这个