如何在react-native-mapbox-gl中获得用户位置?

问题描述 投票:0回答:1

我正在使用react-native-mapbox-gl在我的react应用程序中显示地图,在页面加载时,它应该像google maps一样显示用户的位置,但是它无法显示,而是会显示一些地图的其他区域,

有人可以帮忙吗?

提前感谢。

这是代码段

import { StyleSheet, View } from "react-native";
import MapboxGL from "@react-native-mapbox-gl/maps";

MapboxGL.setAccessToken("<YOUR_ACCESSTOKEN>");

const styles = StyleSheet.create({
  page: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#F5FCFF"
  },
  container: {
    height: 300,
    width: 300,
    backgroundColor: "tomato"
  },
  map: {
    flex: 1
  }
});

export default class App extends Component {
  componentDidMount() {
    MapboxGL.setTelemetryEnabled(false);
  }

  render() {
    return (
      <View style={styles.page}>
        <View style={styles.container}>
          <MapboxGL.MapView style={styles.map} />
          <MapboxGL.UserLocation />
        </View>
      </View>
    );
  }
}
javascript react-native maps mapbox react-native-mapbox-gl
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.