小编use*_*148的帖子

react-native-maps fitToSuppliedMarker/fitToCorodinates 不显示所有标记

我正在尝试使用简单的 MapView 并显示 2 个标记。

它们都在地图视图上正确显示,但在屏幕上不可见(默认渲染 Image1)

在屏幕上可以看到两个标记之前,我必须执行手动拖动操作。(我手动拖动地图后的图像2,以便它们可以在屏幕上看到)

我尝试使用 fitToSuppliedMarkers/fitToCocordinates 但似乎没有任何效果。

export default class FavItemMapView extends Component{

constructor(props){
    super(props)
    this.state={
        position:{
            latitude:1.286353,
            longitude:103.853067,
            latitudeDelta: 0,
            longitudeDelta: 0,
        },
        error:null
    }
    this.mapRef = null;
}

componentWillMount(){

    const favPlaceLatitude = parseFloat(this.props.navigation.state.params.latitude)
    const favPlaceLongitude = parseFloat(this.props.navigation.state.params.longitude)
    markers.push({latitude:favPlaceLatitude,longitude:favPlaceLongitude});
    navigator.geolocation.getCurrentPosition(
        (position) => {
          console.log("wokeeey" + width + height);
          console.log(position);
          var lat = parseFloat(position.coords.latitude)
          var long = parseFloat(position.coords.longitude)

          var initialRegion = {
            latitude: lat,
            longitude: long,
            latitudeDelta: LATITUDE_DELTA,
            longitudeDelta: LONGITUDE_DELTA,
          }

          this.onRegionChange(initialRegion)
        },
        (error) => this.setState({ …
Run Code Online (Sandbox Code Playgroud)

ios react-native react-native-ios react-native-maps

2
推荐指数
1
解决办法
7197
查看次数