Google java 客户端 api 方向 api 给出了错误的路线

Google java client api direction api is giving wrong route

我正在使用 Google 的 JAVA 客户端 API 来获取路由,并且我正在这样发送请求,

   DirectionsRoute[] routes = DirectionsApi.newRequest(context)
                              .mode(TravelMode.DRIVING)
                              .origin(start).destination(end)
                              .waypoints(wayPoints).await();

它也是返回路线,但如果我绘制该路线,它不会绘制在实际路线上,而是采用直线,如图所示。 如何解决?

实际上我在那个请求之后犯了一个错误,我得到了带有路线的结果,但它也包含由 lat lang 数组组成的编码器折线对象,一旦我们解码它,我们就会得到所有的点这样我们就可以正确的获取到路由了。 结果由路线数组组成,每个元素由腿数组(两点之间的路线详细信息)组成,每条腿由步骤组成,最后每个步骤都有编码折线,以便获得正确的 latlang,您应该解码该折线并使用它。

非常感谢你,你帮了我很多,我目前正在使用xamarin并使用这种方法解码折线。

        private List<LatLng> DecodePolyline(string encodedPoints)
    {
        if (string.IsNullOrWhiteSpace(encodedPoints))
        {
            return null;
        }

        int index = 0;
        var polylineChars = encodedPoints.ToCharArray();
        var poly = new List<LatLng>();
        int currentLat = 0;
        int currentLng = 0;
        int next5Bits;

        while (index < polylineChars.Length)
        {
            // calculate next latitude
            int sum = 0;
            int shifter = 0;

            do
            {
                next5Bits = polylineChars[index++] - 63;
                sum |= (next5Bits & 31) << shifter;
                shifter += 5;
            }
            while (next5Bits >= 32 && index < polylineChars.Length);

            if (index >= polylineChars.Length)
            {
                break;
            }

            currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);

            // calculate next longitude
            sum = 0;
            shifter = 0;

            do
            {
                next5Bits = polylineChars[index++] - 63;
                sum |= (next5Bits & 31) << shifter;
                shifter += 5;
            }
            while (next5Bits >= 32 && index < polylineChars.Length);

            if (index >= polylineChars.Length && next5Bits >= 32)
            {
                break;
            }

            currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);

            var mLatLng = new LatLng(Convert.ToDouble(currentLat) / 100000.0, Convert.ToDouble(currentLng) / 100000.0);
            poly.Add(mLatLng);
        }

        return poly;
    }