我到处寻找,除了请求用户的 GPS 位置之外找不到解决方案。一旦有人下载了应用程序,有没有办法提供诸如国家/地区之类的信息?
示例:
允许在美国下载 允许在西班牙下载
根据地区,我们会默认使用特定语言。或者除了GPS定位器就没有办法了吗?因为如果是这样的话,也许在注册时询问更喜欢哪种语言将是我的解决方案。
感谢您的洞察力。
答案 0 :(得分:0)
如果我理解,GPS 就不需要提示语言了。使用系统偏好设置,我认为这个包可以帮助https://github.com/zoontek/react-native-localize。
答案 1 :(得分:0)
据我所知,您需要在不使用 GPS 的情况下获取用户所在国家/地区。好吧,您可以使用 freegeoip.app/json API 以 JSON 格式返回用户当前位置的纬度、经度、国家名称、州、城市/城镇。
state = {
countryData:null,
};
componentDidMount() {
fetch('https://freegeoip.app/json/', {
method: 'GET'
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
this.setState({
countryData: responseJson,
})
})
.catch((error) => {
console.error(error);
});
}
<Text>{this.state.countryData.country_name}</Text>