找不到折线的路线点

时间:2019-10-23 10:35:22

标签: react-native google-api polyline react-native-maps

Google api返回一个与路线无关的点。

                const mode = 'walking'; 
                const origin = {latitude:   50.0147419184446 , longitude: 36.224892940495984};
                const destination = {latitude:   50.0147419184446  + 0.1, longitude: 36.224892940495984};
                const APIKEY = 'ХХХХХХХХХХХХХ';
                const url = `https://maps.googleapis.com/maps/api/directions/json?origin=${origin}&destination=${destination}&key=${APIKEY}&mode=${mode}`;

              fetch(url)
                    .then(response => response.json())
                    .then(responseJson => {
                        if (responseJson.routes.length) {
                            let array = Polyline.decode(responseJson.routes[0].overview_polyline.points)
                                let coordinates = array.map((point) => {
                                return  {
                                    latitude :point[0],
                                    longitude :point[1]
                                }
                            })
                            this.setState({
                                coords: coordinates
                            }, () => { console.log(this.state.coords)});
                        }
                    }).catch(e => {
                    console.warn(e)
                });

coordinates变量仅包含一个与我们的路线无关的点。

0 个答案:

没有答案