I am using geolocation in react-native with redux, but I am getting 2 problems..
Can anyone help me?
Here is my code..!
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