Mapview博览会的默认位置

时间:2020-01-31 03:37:09

标签: react-native maps expo

我有一个简单的世博会地图,如下所示:

<MapView
    loadingEnabled
    ref = {c => (this.mapView = c)}
    style={ styles.mapStyle }
>
    {jobsToArray.map(function(item, i){
        return <MapView.Marker
            key={i}
            coordinate={item}
        >
        </MapView.Marker>
    })}
    <MapViewDirections
        mode="DRIVING"
        optimizeWaypoints={true} //Make sure route is the fatest possible
        origin={this.state.myLocation.coords} //Start location = current location
        waypoints={jobsToArray} //Array of destinations to visit
        destination={jobsToArray[jobsToArray.length-1]} //Final destination
        onReady={result => {
            //Show entire map of waypoints with some padding
            this.mapView.fitToCoordinates(result.coordinates, {
                edgePadding: {
                    right: width / 20,
                    bottom: height / 20,
                    left: width / 20,
                    top: height / 3
                }, animated: true }
            );
        }}
        onError={errorMessage => {
            // console.log('GOT AN ERROR');
        }}
    />
</MapView>`

该地图会显示所有位置的动画,并且效果很好,但是我有点讨厌,在我加载方向之前,地图的起始位置是非洲中部(尽管显示了整个国家),但将动画扫描到澳大利亚的郊区。无论如何,要显示澳大利亚(或确切的位置)然后从那里放大?

理想情况下,我将向我们展示我们的地图正在使用的州,然后从那里进行较小的缩放。我希望这是有道理的。

谢谢

1 个答案:

答案 0 :(得分:0)

有一些简单的代码可添加到MapView

initialRegion={{ latitude: -37.112146, longitude: 144.857483, latitudeDelta: 10, longitudeDelta: 10, }}