【问题标题】:React-native : how to get coordinates and delta of visible area in MapView componentReact-native:如何在 MapView 组件中获取可见区域的坐标和增量
【发布时间】:2016-02-27 10:18:46
【问题描述】:

假设我以这种方式在 react native 中定义了一个地图:

    render() {
        return (
            <View style={{flex: 1, position: 'relative'}}>
                <MapView
                    style={styles.map}
                    showsUserLocation={this.state.showsUserLocation}
                    region={{
                        latitude: 48.8534100,
                        longitude: 2.3378000,
                        latitudeDelta: 0.12,
                        longitudeDelta: 0.065
                    }}
                    onRegionChangeComplete={
                        () => {
                            // How to retrieve coordinates and Delta when user moves the map
                            console.log(this.region);
                        }
                    } />
            </View>
        );
    }

用户在地图上移动时如何获取坐标和Delta?

【问题讨论】:

    标签: javascript components coordinates react-native


    【解决方案1】:

    这是执行此操作的一种方法...

    在你的 render() 函数中,像这样设置 onRegionChangeComplete:

    onRegionChangeComplete={this.onRegionChangeComplete}
    

    然后在你的组件中定义回调函数,例如在 render() 函数下方:

    onRegionChangeComplete: function(region) {
        console.log(region.longitude);
        console.log(region.latitude);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      相关资源
      最近更新 更多