如何使用MAPS API的OptimizeWaypoints配置重定向到地图页面?

发布于 2025-01-18 08:58:39 字数 1313 浏览 2 评论 0原文

我在我的应用程序中使用地图 api,当我要查看创建的路线时,我可以选择设置 optimizeWaypoints = true 来组织航路点,但是...我需要在谷歌地图页面上查看该路线,但每当我尝试时路径点没有“优化”。

我是这样做的:

for (var i = 0; i < wayptss.length; i++) {string_de_waypoints += wayptss[i] + '/';} var addresses = string_de_waypoints;

 var address2 = document.getElementById("end").value;

 // window.open("https://maps.google.ch/maps?saddr=["+address1+"]&daddr=["+address2+"] to:["+address3+"] to: ["+address4+"]to: ["+address5+"]")

        link_maps = "https://www.google.ch/maps/dir/"+address1+"/"+addresses+address2;
        window.open(link_maps)

值来自这里:

 const waypts = [];
        const checkboxArray = document.getElementById("waypoints");
        wayptss=[];
        for (let i = 0; i < checkboxArray.length; i++) {
            if (checkboxArray.options[i].selected) {
            waypts.push({
                location: checkboxArray[i].value,
                stopover: true,
            });
            //-----------------HERE--------------------------------
            wayptss.push(checkboxArray[i].value,
            );
            }

输入地址工作人员

好吧..我想知道的是,我是否有办法做到这一点,例如直接将路线导出到谷歌地图或类似的东西。 或者,如果不是至少一种通过获取他的距离或类似的东西来优化路线航点数组的方法。

I'm using maps api in my app and when i what to see the created route i have the choice of set optimizeWaypoints = true to organize the waypoints but... I need to see that route on google maps page, but whenever i try that the way points are not "optimized".

I have done this that way:

for (var i = 0; i < wayptss.length; i++) {string_de_waypoints += wayptss[i] + '/';} var addresses = string_de_waypoints;

 var address2 = document.getElementById("end").value;

 // window.open("https://maps.google.ch/maps?saddr=["+address1+"]&daddr=["+address2+"] to:["+address3+"] to: ["+address4+"]to: ["+address5+"]")

        link_maps = "https://www.google.ch/maps/dir/"+address1+"/"+addresses+address2;
        window.open(link_maps)

The value come from here:

 const waypts = [];
        const checkboxArray = document.getElementById("waypoints");
        wayptss=[];
        for (let i = 0; i < checkboxArray.length; i++) {
            if (checkboxArray.options[i].selected) {
            waypts.push({
                location: checkboxArray[i].value,
                stopover: true,
            });
            //-----------------HERE--------------------------------
            wayptss.push(checkboxArray[i].value,
            );
            }

the input adresses staff

Well... What i want to know is, if I have some way to do that like exporting directly the route to google maps or something like that.
Or if not at least a way to optimize the route waypoints array by getting his distance or something like that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水波映月 2025-01-25 08:58:39

好吧,我找到了解决方案。
我用过这个:

summaryPanel.innerHTML += route.legs[i].start_address + " to ";
summaryPanel.innerHTML += route.legs[i].end_address + "<br>";
summaryPanel.innerHTML += route.legs[i].distance.text + "<br><br>";

https://developers.google.com/maps/documentation/javascript/方向

Ok i found a solution.
I used this:

summaryPanel.innerHTML += route.legs[i].start_address + " to ";
summaryPanel.innerHTML += route.legs[i].end_address + "<br>";
summaryPanel.innerHTML += route.legs[i].distance.text + "<br><br>";

https://developers.google.com/maps/documentation/javascript/directions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文