【问题标题】:Google Direction service giving wrong route谷歌方向服务给出错误的路线
【发布时间】:2020-12-03 13:39:31
【问题描述】:

使用以下坐标在地图上绘制 googlemap 路线。但路线错误。问题出在哪里?

LNG                    LAT
58.5589893333333       23.6229513333333   Start
58.5589985             23.6231225         WAY POINT 1
58.5591366666667       23.6235491666667   WAY POINT 2
58.55882               23.6236481666667   WAY POINT 3
58.5476361666667       23.6209141666667   WAY POINT 4
58.5454098333333       23.616038          END

走错路

在谷歌地图网站上尝试了相同的坐标,它给出了正确的方法

问题出在哪里?正确发送所有航点、起点和目的地。坐标来自跟踪设备。只有某些情况下会显示这样的错误路线。

var directionDisplay;
var directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer();     
directionsDisplay.setMap(map);
var first = new google.maps.LatLng(23.6231225,58.5589985);
var second = new google.maps.LatLng(23.6235491666667,58.5591366666667);
var third = new google.maps.LatLng(23.6236481666667,58.55882);
var forth = new google.maps.LatLng(23.6209141666667,58.5476361666667); 
var i = 0;
var start = StartlatDir[i]+','+StartlongDir[i];
var end = EndlatDir[i] + ',' + EndlongDir[i];
var request = {
    origin: start,
    destination: end,
    waypoints: [{ location:first, stopover: false },
        { location: second, stopover: false },
        { location: third, stopover: false },
        { location: forth, stopover: false }],
    optimizeWaypoints: false,
    travelMode: google.maps.DirectionsTravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC
};
directionsService.route(request, function (response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
        var myRoute = response.routes[0];
        var txtDir = '';
        for (var i = 0; i < myRoute.legs[0].steps.length; i++) {
            txtDir += myRoute.legs[0].steps[i].instructions + "<br />";
        }
    }
});

【问题讨论】:

  • 什么是StartlatDir[i]StartlongDir[i]EndlatDir[i] &EndlongDir[i]?请提供一个 minimal reproducible example 来证明您的问题。
  • 起始值为 58.5589893333333 23.6229513333333 终止值为 58.5454098333333 23.616038
  • edit你的问题解决cmets。
  • @user6753632 你有没有找到任何解决方案。

标签: javascript google-maps directions


【解决方案1】:

DirectionsService 对出口附近(或道路错误一侧)的航路点非常敏感。

Waypoint 4 (23.6209141666667, 58.5476361666667) 使路线离开出口。

沿着通往(23.620315,58.5471)的道路进一步移动,得到预期的路线:

fiddle

或完全删除它会给出预期的路线

fiddle

【讨论】:

  • 非常感谢您宝贵的时间...这里的问题是我无法编辑航点或删除航点...所有点都来自车辆跟踪设备...我拿走了很少有位置数据作为示例来轻松描述问题......所以我们在不同道路的路线中面临这种类型的问题,具有不同的 gprs 数据............我可以问一下,Will Snap to road功能解决了这个问题?是否可以通过像jsfiddle.net/Rohith_KP/dk1zp2n8 这样的道路路线为车辆设置动画?
  • Snap to road 可能会解决这个问题,它也可能有同样的问题(因为它使用相同的基础数据)。你试过了吗?一旦你得到你想要的正确路线,你应该能够像fiddle那样做动画
  • 捕捉到道路会产生其他问题..只有当位置非常接近时才会成功..请查看具有相同坐标的此链接..为什么路线直到终点才显示..我不确定......developers-dot-devsite-v2-prod.appspot.com/maps/documentation/…
  • 每个位置数据将首先捕捉到道路,然后使用捕捉的点调用方向请求?它会解决问题吗?知道如何只捕捉到一个点(纬度,经度)以及如何获得这个捕捉位置数据?
猜你喜欢
  • 2017-02-23
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 2015-02-25
  • 1970-01-01
  • 2019-07-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多