Directions between Two-point location in mapbox-gl - React Native?

后端 未结 1 1962
栀梦
栀梦 2020-12-07 06:15

I have two point i get it from database and i want to render a line From start point to end point

what I got is the Straight line in two points without consideratio

相关标签:
1条回答
  • 2020-12-07 06:41

    Use Google Maps Direction API where you will get encoded polyline and you can decode that encoded Polyline using following function

    decode(t, e) {
            for (
                var n,
                o,
                u = 0,
                l = 0,
                r = 0,
                d = [],
                h = 0,
                i = 0,
                a = null,
                c = Math.pow(10, e || 5);
                u < t.length;
    
            ) {
                (a = null), (h = 0), (i = 0);
                do (a = t.charCodeAt(u++) - 63), (i |= (31 & a) << h), (h += 5);
                while (a >= 32);
                (n = 1 & i ? ~(i >> 1) : i >> 1), (h = i = 0);
                do (a = t.charCodeAt(u++) - 63), (i |= (31 & a) << h), (h += 5);
                while (a >= 32);
                (o = 1 & i ? ~(i >> 1) : i >> 1),
                    (l += n),
                    (r += o),
                    d.push([l / c, r / c]);
            }
            return (d = d.map(function (t) {
                return { latitude: t[0], longitude: t[1] };
            }));
        }

    This Will return required data for polyline.

    0 讨论(0)
提交回复
热议问题