小编use*_*865的帖子

Google Maps v3在两点之间创建路线

我正在使用Google Maps API开发Web应用程序.我试图在两点之间创建一条路线但由于某种原因我还没弄明白如何创建它.以下是我的代码,请告诉我是否有遗漏的内容.谢谢.

<script>
var Center=new google.maps.LatLng(18.210885,-67.140884);
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
  directionsDisplay = new google.maps.DirectionsRenderer();
var properties = {
    center:Center,
    zoom:20,
    mapTypeId:google.maps.MapTypeId.SATELLITE
};

map=new google.maps.Map(document.getElementById("map"), properties);
directionsDisplay.setMap(map);

var marker=new google.maps.Marker({
position:Center,
animation:google.maps.Animation.BOUNCE,
});

marker.setMap(map);

}

function Route() {

var start = new google.maps.LatLng(18.210885,-67.140884);
var end =new google.maps.latLng(18.211685,-67.141684);
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.WALKING
 };
 directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
  directionsDisplay.setDirections(result);
}
});
} 

google.maps.event.addDomListener(window,'load',initialize);
</script>
Run Code Online (Sandbox Code Playgroud)

routes google-api google-maps-api-3

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

google-api ×1

google-maps-api-3 ×1

routes ×1