1

我已将 react native 地图与我最新的 react native 应用程序集成在一起。在地图中,我想为地图设置边界。官方文档建议了该方法 setMapBoundaries ,但它需要这样的论点northEast: LatLng, southWest: LatLng

我怎样才能获得这些参数的值。我的mapView是这样的。

<MapView
            showsUserLocation
            provider={MapView.PROVIDER_GOOGLE}
            style={styles.map}
            region={region}
            onRegionChangeComplete={this.onRegionChangeComplete}
            setMapBoundaries={}
            onUserLocationChange={this.onUserLocationChange}

        > 
4

1 回答 1

3

您尝试使用的不是propertyor event,而是method. 所以你不能在那里使用它。再次检查文档

setMapBoundaries(northEast: LatLng, southWest: LatLng): void;

export interface LatLng {
   latitude: number;
   longitude: number;
}

尝试获取refMapView 的,

<MapView
    ref={(ref)=> this.mapRef = ref}
/>

并调用方法setMapBoundaries

this.mapRef.setMapBoundaries({latitude: 1, longitude: 1},{latitude: 1, longitude: 1})

于 2018-07-20T05:37:55.373 回答