Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否可以在不使用JSON的情况下向Google Maps API添加航路点?_Javascript_Asp.net Mvc 2_Google Maps - Fatal编程技术网

Javascript 是否可以在不使用JSON的情况下向Google Maps API添加航路点?

Javascript 是否可以在不使用JSON的情况下向Google Maps API添加航路点?,javascript,asp.net-mvc-2,google-maps,Javascript,Asp.net Mvc 2,Google Maps,我使用的是ASP.NETMVC,我使用的是带有Javascript的谷歌地图API。我向视图发送一个模型,其中包含一个或多个要添加到路线的航路点 function calcRoute() { initialize(); var start = "<%= Model.StartAddress %>"; var end = "<%= Model.ClientAddress %>"; var wa

我使用的是ASP.NETMVC,我使用的是带有Javascript的谷歌地图API。我向视图发送一个模型,其中包含一个或多个要添加到路线的航路点

        function calcRoute() {
        initialize();
        var start = "<%= Model.StartAddress %>";
        var end = "<%= Model.ClientAddress %>";

        var waypts = [];

        waypts.push({
            location: "<%= Model.PickupAddress[0] %>",
            stopover:true
        });

        var request = {
            origin: start,
            destination: end,
            waypoints: waypts,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };

        directionsService.route(request, function (response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            }
        });
    }
函数calcRoute(){
初始化();
var start=“”;
var end=“”;
var-waypts=[];
推({
地点:“,
中途停留:对
});
var请求={
来源:start,
目的地:完,
航路点:航路点,
travelMode:google.maps.Directions travelMode.DRIVING
};
路由(请求、功能(响应、状态){
if(status==google.maps.directionstatus.OK){
方向显示。设置方向(响应);
}
});
}

可以用Model.PickupAddress数组中的地址以这种方式添加航路点吗?我见过使用JSON(用于标记)的示例代码,但如果我可以直接在Javascript代码中使用,那对我来说就太好了。

这太过时了。然而,不清楚你想要实现什么。JSON只是一种指定javascript对象的轻量级或简短方式。最好看到一个XHR来检索一些值。因为似乎每个刷新的视图都会有这样的代码。多个地址怎么样?没错,不太清楚。我想知道是否可以使用JSON来填充waypoints数组。但是为了解决这个问题,我们在PickUpAddress数组中使用了一个ASP foreach循环来遍历地址。我不知道这是否是最好的解决方案,但它是有效的。