【发布时间】:2019-02-13 05:39:34
【问题描述】:
我在带有 redux 的 react-native 中使用地理定位,但我遇到了 2 个问题..
- 在我的 android studio 模拟器中显示错误的纬度和经度,我的位置是巴基斯坦拉合尔,但它显示的是美国位置。
- 当我签署了 apk 文件并将该 apk 文件安装到我的手机中时,它没有显示任何位置,为空。
谁能帮帮我?
这是我的代码..!
Reducer.js
let initialState = {
lng: null,
lat: null,
}
export default function prayerTimes(state = initialState, action) {
switch (action.type) {
case GET_LOCATION:
return {
...state,
lat: action.lat,
lng: action.lng
}
}
}
Action.js
export function getLocation() {
return dispatch => {
navigator.geolocation.getCurrentPosition((position) => {
dispatch({
type: GET_LOCATION,
lat: position.coords.latitude,
lng: position.coords.longitude
});
});
};
}
App.js
componentDidMount() {
const { getLocation } = this.props;
getLocation();
}
render() {
const { lng, lat } = this.props;
return (
<View style={{justifyContent: 'center'}}>
<Text style={{color: 'white'}}>Latitude: {lat}</Text>
<Text style={{color: 'white'}}>Latitude: {lng}</Text>
</View>
);
}
【问题讨论】:
标签: api react-native redux geolocation maps