我已经在react-native redux中创建了祷告时间应用,并且已经在Prayer Times中实现了地理位置,它在android studio模拟器中运行,但是当我为此应用创建apk文件并将其安装在我的手机上时,地理位置却没有工作,它显示了移动设备的初始状态。
我已经很多次发布过这个问题了,但是没人回答。
有人可以帮我吗?
Reducer.js
let initialState = {
latitude: 0,
longitude: 0,
}
export default function prayerTimes(state = initialState, action) {
switch (action.type) {
case GET_LOCATION:
return Object.assign({},
state,
{
latitude: action.latitude,
longitude: action.longitude
}
)
default:
return state;
}
}
Action.js
export function getLocation() {
return dispatch => {
navigator.geolocation.getCurrentPosition(
(position) => {
dispatch({
type: GET_LOCATION,
latitude: position.coords.latitude,
longitude: position.coords.longitude
});
},
(error) => { },
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 60 * 60 * 24, showLocationDialog: true },
);
};
}
Main.js
componentDidMount() {
const { getLocation } = this.props;
getLocation();
}
render() {
const { latitude, longitude } = this.props;
return (
<View>
<Text>Latitude: {latitude}</Text>
<Text>Longitude: {longitude}</Text>
</View>
);
}
}