zoukankan      html  css  js  c++  java
  • RN 获取地理位置

    代码:

    export default class GeolocationView extends Component {
        watchID: number;
    
        constructor(props){
            super(props)
            this.state={
                lastPosition:''
            }
        }
    
        getPosition(){
            navigator.geolocation.getCurrentPosition(
                (position) => {
                    var initialPosition = JSON.stringify(position);
                    console.log('initialPosition:'+initialPosition)
                    this.setState({initialPosition});
                    alert(initialPosition);
                },
                (error) => alert(JSON.stringify(error)),
                {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
            );
            this.watchID = navigator.geolocation.watchPosition((position) => {
                var lastPosition = JSON.stringify(position);
                this.setState({lastPosition});
            });
        }
    
        render() {
            return (
                <View style={styles.container}>
                    <TouchableOpacity style={styles.button} onPress={() => this.getPosition()}>
                        <Text >获取定位信息,{this.state.lastPosition}</Text>
                    </TouchableOpacity>
                </View>
            );
        }
    }
    
    const styles = StyleSheet.create({
        container: {
            flex: 1,
            marginTop: 200,
            alignItems: 'center',
        },
        button: {
            marginTop: 20,
            backgroundColor: '#808080',
            height: 35,
             140,
            borderRadius: 5,
            justifyContent: 'center',
            alignItems: 'center',
        },
    });
    
  • 相关阅读:
    CF547D Mike and Fish
    CF147B Smile House
    [BJOI2017]树的难题
    AT2306 Rearranging
    复利计算器--单元测试
    操作系统 实验1 命令解释程序的编写
    个人项目耗时对比记录表
    复利计算器3.0
    0320记《构建之法》读后感
    复利计算实验总结
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/10190283.html
Copyright © 2011-2022 走看看