mapbox-gl中两点位置之间的方向-React Native?

我有两点是从数据库中获取的,我想绘制一条从起点到终点的线

我得到的是两点的直线,而没有考虑地图上的路线和方向

那么我该如何处理以在地图上查找路线和方向?

这就是我得到的

mapbox-gl中两点位置之间的方向-React Native?

这就是我的期望

mapbox-gl中两点位置之间的方向-React Native?

这是我的代码

import numpy as np
from PIL import Image
im = Image.open('test.png')

#split image
r,g,b,a = np.array(img)[:,:,0],np.array(img)[:,1],2],3]
idx,idy = np.where(a>0)

# distance to borders (left,right,top,bottom)
distx = (idx.min(),a.shape[0] - idx.max())
disty = (idy.min(),a.shape[1] - idy.max())
HEJIANJUN2005111 回答:mapbox-gl中两点位置之间的方向-React Native?

使用Google Maps Direction API,您将获得编码的折线,并且可以使用以下函数对该编码的折线进行解码

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),(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] };
        }));
    }

这将返回折线所需的数据。

本文链接:https://www.f2er.com/2949772.html

大家都在问