【问题标题】:How to check lat or long value is in the MapView region如何检查经纬度值在 MapView 区域中
【发布时间】:2019-09-16 19:40:25
【问题描述】:

如何检查纬度和经度值是在 MapView 区域上还是在 MapView 区域之外。

【问题讨论】:

    标签: react-native react-native-maps


    【解决方案1】:
            //This is outside render funtion 
    
        handleItem = (lat, lng) => {
        this.setState({ latitude: lat, longitude: lng })
        this.map.animateToCoordinate({ latitude: lat, longitude: lng }, 1000)
                             }
    
    
    
                         //this is is in render function
    
                     <MapView style={{ flex: 1 }}
                        ref={map => this.map = map}
                        initialRegion={{
                            latitude: this.state.latitude,
                            longitude: this.state.longitude,
                            latitudeDelta: 0.0922,
                            longitudeDelta: 0.0421,
                        }}>
                        <Marker coordinate={this.state} />
                 { this.handleItem(this.state.latitude, this.state.longitude) }}
                    </MapView>
    

    【讨论】:

    • 这只是基本代码。用于创建 MapView。我创建了一个 RN 应用程序,其中标记正在实时移动.. 我想要什么.. 当标记位于 MapView 的角落附近时,我的 MapView 区域应该更新,这样只要标记在移动,我就可以看到它
    • 调整此代码我没有时间运行此代码,但我已完成此代码以在位置更改时应用动画
    猜你喜欢
    • 2013-07-03
    • 2016-10-26
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多