LocationTextView.js
1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, {Component} from 'react';
import {
View,
Text,
TouchableOpacity,
NativeModules
} from 'react-native';
export default class LocationTextView extends Component {
constructor(props) {
super(props);
this.state = {
address: ''
}
}
getAddress() {
let _this = this;
NativeModules.system.getLocation().then(data => {
console.log('address', data);
if (!!JSON.parse(data).cityCode) {
let addressData = JSON.parse(data);
_this.setState({
address: addressData.formattedAddress
});
} else {
return;
}
});
}
render() {
return (
<View style={{width: '100%', backgroundColor: 'white', paddingHorizontal: 5, paddingVertical: 10, flexDirection: 'row'}}>
<Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>当前地点</Text>
<Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)', flex: 1, marginLeft: 30, marginRight: 10}}>{this.state.address}</Text>
<Text style={{fontSize: 16, color: global.homeColor}} onPress={()=>this.getAddress()}>
{(this.state.address && this.state.address.length > 0) ? '刷新':'获取'}</Text>
</View>
);
}
}