【问题标题】:How to set boundaries for react native MapView?如何为反应原生 MapView 设置边界?
【发布时间】:2018-07-20 04:42:08
【问题描述】:

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

如何获取这些参数的值。我的 ma​​pView 是这样的。

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

        > 

【问题讨论】:

    标签: react-native react-native-maps react-android


    【解决方案1】:

    您尝试使用的不是property 或event,而是method。所以你不能在那里使用它。再次检查documentation。

    setMapBoundaries(northEast: LatLng, southWest: LatLng): void;
    
    export interface LatLng {
       latitude: number;
       longitude: number;
    }
    

    尝试获取MapView的ref,

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

    并调用方法setMapBoundaries

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

    【讨论】:

    • 知道了。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 2021-04-05
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    • 2017-11-26
    相关资源
    最近更新 更多