I am unable to use geolocation in react-native with redux

I am using geolocation in react-native with redux, but I am getting 2 problems..

  1. It's showing wrong latitude and longitude in my android studio emulator, my location is lahore, pakistan but It's showing USA location.
  2. When i signed it apk file and installed that apk file in my mobile then It's not showing any location, empty.

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

5 Likes8.20 GEEK