Get Directions between two points in Mapbox?

拜拜、爱过 提交于 2019-12-20 05:38:16

问题


I recently using mapbox gl on react native instead of Google maps, I am trying to add a feature that shows a direction from point A to point B on the map.

OR use Mapbox directions API inside my React Native App

here is my code I tried but after my screen mounted, the app crashed successfully :D

import MapboxGL from '@react-native-mapbox-gl/maps';
import React from 'react';
import {View} from 'react-native';

MapboxGL.setAccessToken(
  '....',
);

class TwoPoints extends React.Component {
  constructor(props) {
    super(props);

    this.featureCollection = {
      type: 'FeatureCollection',
      features: [
        {
          type: 'Feature',
          id: '9d10456e-bdda-4aa9-9269-04c1667d4552',
          properties: {
            icon: 'example',
          },
          geometry: {
            type: 'Point',
            coordinates: [-73.989, 40.733],
          },
        },
        {
          type: 'Feature',
          id: '9d10456e-bdda-4aa9-9269-04c1667d4552',
          properties: {
            icon: 'airport-15',
          },
          geometry: {
            type: 'Point',
            coordinates: [-74, 40.733],
          },
        },
        {
          type: 'Feature',
          id: '9d10456e-bdda-4aa9-9269-04c1667d4552',
          properties: {
            icon: 'pin',
          },
          geometry: {
            type: 'Point',
            coordinates: [-74, 40.733],
          },
        },
      ],
    };
  }
  render() {
    return (
      <View style={{flex: 1}}>
        <MapboxGL.MapView
          ref={c => (this._map = c)}
          zoomEnabled={true}
          style={{flex: 1}}>
          <MapboxGL.ShapeSource shape={this.featureCollection}>
            <MapboxGL.SymbolLayer
              style={{iconColor: 'red'}}
              minZoomLevel={25}
            />
          </MapboxGL.ShapeSource>
        </MapboxGL.MapView>
      </View>
    );
  }
}
export default TwoPoints;

来源:https://stackoverflow.com/questions/59255333/get-directions-between-two-points-in-mapbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!