有没有办法在移动设备上找到客户的位置?例如,如果用户打开应用程序,我如何才能找到他们的大致位置?
例如,如果一个用户来自旧金山CA,它将有一些类型标识符,让我知道用户来自旧金山CA.我不需要他们的确切位置,只是县或一般地区的原产地.
我有个推荐人:This SO Question
有没有办法在移动设备上找到客户的位置?例如,如果用户打开应用程序,我如何才能找到他们的大致位置?
例如,如果一个用户来自旧金山CA,它将有一些类型标识符,让我知道用户来自旧金山CA.我不需要他们的确切位置,只是县或一般地区的原产地.
我有个推荐人:This SO Question
当然基于该线程中的一个答案,您可以像这样在React Native中实现-
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
export default class Test extends Component {
constructor(props) {
super(props);
this.state = {
countryName: '',
regionName: ''
};
}
componentDidMount() {
var url = 'https://freegeoip.net/json/';
fetch(url)
.then((response) => response.json())
.then((responseJson) => {
//console.log(responseJson);
this.setState({
countryName: responseJson.country_name,
regionName: responseJson.region_name
});
})
.catch((error) => {
//console.error(error);
});
}
render() {
return (
<View style={styles.container}>
<Text>Country: {this.state.countryName}</Text>
<Text>Region: {this.state.regionName}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});
AppRegistry.registerComponent('Test', () => Test);