react-native-geolocation
react-native-geolocation copied to clipboard
unable to get my current location
Ask your Question
I'm unable to get my current location using this code
import React from 'react';
import {View, Text, StyleSheet, Alert} from 'react-native';
import MapView, {PROVIDER_GOOGLE} from 'react-native-maps';
import {hp, wp, deviceWidth, deviceHeight} from '../../components/common';
import {ScrollView} from 'react-native-gesture-handler';
import {MapStyle} from './map-style';
import Geolocation from '@react-native-community/geolocation';
class MapPage extends React.Component {
componentDidMount() {
this.locateCurrentPosition();
}
locateCurrentPosition = () => {
Geolocation.getCurrentPosition(
(position) => {
console.log(JSON.stringify(position));
let initialPosition = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
latitudeDelta: 0.09,
longitudeDelta: 0.035,
};
this.setState({initialPosition});
},
(error) => Alert.alert(error.message),
{enableHighAccuracy: true, timeout: 10000, maximumAge: 1000},
);
};
render() {
return (
<ScrollView style={styles.container}>
<MapView
provider={PROVIDER_GOOGLE}
customMapStyle={MapStyle}
style={{
height: deviceHeight - hp(20),
width: deviceWidth,
borderWidth: 1,
}}
region={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}></MapView>
</ScrollView>
);
}
}
export default MapPage;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
// width: deviceWidth,
minHeight: deviceHeight,
},
});
or check this link here
I am having the same problem, the code simply doesn't run and I am not getting any errors? Have you resolved this? It used to work before rn-community was the new norm...
@rajibola how did u solve it ?
@kukuandroid Hey, try going to your simulator settings and do the following: Features > Location > Custom Location (Change location). This solved it for me for some reason.
i tried it already. strange
On Mon, Nov 2, 2020 at 1:17 AM Hugo [email protected] wrote:
@kukuandroid https://github.com/kukuandroid Hey, try going to your simulator settings and do the following: Features > Location > Custom Location (Change location). This solved it for me for some reason.
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/react-native-geolocation/react-native-geolocation/issues/119#issuecomment-720121522, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJBJR223AQMC4ASWU3WSSDSNWJY7ANCNFSM4QS57MZQ .
--
Thanks and Regards,
MUHAMAD KHAIRUL FILHAN BIN NUSI
Co-founder / Fullstack Developer KukuBytes Solution
experiencing the same here. getCurrentPosition does not call success neither error.
switch to geolocation-service, its proven on production
On Thu, Nov 12, 2020 at 4:40 PM hossamnasser938 [email protected] wrote:
experiencing the same here. getCurrentPosition does not call success neither error.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/react-native-geolocation/react-native-geolocation/issues/119#issuecomment-725930646, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJBJR2CBH75GDZZBI3TJTTSPONQ5ANCNFSM4QS57MZQ .
--
Thanks and Regards,
MUHAMAD KHAIRUL FILHAN BIN NUSI
Co-founder / Fullstack Developer KukuBytes Solution
@kukuandroid Hey, try going to your simulator settings and do the following: Features > Location > Custom Location (Change location). This solved it for me for some reason.
This was a solution for me, on macbook pro m1, with IOS emulator, THANKS!
Hello, are there any solutions currently?
Hello, are there any solutions currently?
Did you already try this?
@kukuandroid Hey, try going to your simulator settings and do the following: Features > Location > Custom Location (Change location). This solved it for me for some reason.