react-native-geolocation icon indicating copy to clipboard operation
react-native-geolocation copied to clipboard

unable to get my current location

Open rajibola opened this issue 4 years ago • 9 comments

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

rajibola avatar Sep 02 '20 12:09 rajibola

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...

nica0012 avatar Oct 29 '20 17:10 nica0012

@rajibola how did u solve it ?

kukuandroid avatar Nov 01 '20 16:11 kukuandroid

@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.

nica0012 avatar Nov 01 '20 17:11 nica0012

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

kukuandroid avatar Nov 01 '20 17:11 kukuandroid

experiencing the same here. getCurrentPosition does not call success neither error.

hossamnasser938 avatar Nov 12 '20 08:11 hossamnasser938

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 avatar Nov 12 '20 08:11 kukuandroid

@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!

poleselfg avatar Aug 12 '21 14:08 poleselfg

Hello, are there any solutions currently?

Mariam-K-code-care avatar Dec 13 '21 06:12 Mariam-K-code-care

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.

poleselfg avatar Dec 29 '21 19:12 poleselfg