我最近在 React Native 上使用 Mapbox gl 而不是 Google 地图,
我正在尝试添加一个功能,显示地图上从 A 点到 B 点的方向。
OR use Mapbox 路线 API https://docs.mapbox.com/help/how-mapbox-works/directions/在我的 React Native 应用程序中
这是我尝试过的代码,但在安装屏幕后,应用程序成功崩溃: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;