Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while trying to get user current location. #283

Open
elkee2003 opened this issue Nov 17, 2023 · 0 comments
Open

Error while trying to get user current location. #283

elkee2003 opened this issue Nov 17, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@elkee2003
Copy link

elkee2003 commented Nov 17, 2023

Environment

Screenshot (75)

react-native : The term 'react-native' is not recognized
as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and
try again.
At line:1 char:1

  • react-native info
  •   + CategoryInfo          : ObjectNotFound: (react-nati  
     ve:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException 
    
    
    

Platforms

Android

Versions

  • Android:
  • iOS:
  • react-native-geolocation: 3.1.0
  • react-native: 0.72.7
  • react: 18.2.0
    Screenshot (76)

Description

`import { View, useWindowDimensions, PermissionsAndroid, Platform, Pressable, ActivityIndicator } from 'react-native'
import React, {useState, useEffect} from 'react'
import Geolocation from '@react-native-community/geolocation';
import MapView, {PROVIDER_GOOGLE, Marker} from 'react-native-maps';

const GOOGLE_MAPS_APIKEY = '*';

const HomeScreen = () => {
const {width, height}= useWindowDimensions()
const [myPosition, setMyPosition] = useState(null)

// useEffect Hook for Location

useEffect(() => {
const requestLocationPermission = async () => {
if (Platform.OS === 'android') {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Atua Location Request',
message: 'Atua needs access to your location.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted === PermissionsAndroid.RESULTS.DENIED) {
console.log('Location permission denied');
return;
}
}

  Geolocation.getCurrentPosition(
    (position) => {
      console.log(position)
      const {latitude, longitude}=position.coords;
      setMyPosition({latitude,longitude})
    },
    (error) => {
      console.log(error);
    },
    { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 },
  );
};

requestLocationPermission();

}, []);

return (

<MapView
style={{width, height:height-150}}
provider={PROVIDER_GOOGLE}
showsUserLocation
initialRegion={{
latitude: myPosition.latitude,
longitude: myPosition.longitude ,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
<Marker
title={'hi'}
description={'Good'}
coordinate={{
latitude:37.43199,
longitude:-122.099
}}/>


)
}

export default HomeScreen`
Screenshot (77)
Screenshot (79)

Screenshot (78)

This code in one of my applications works smoothly. On rendering the screen it shows my currentpositon in the intial region. However this doesn't work for my other applications, I wonder why? This is the error it shows
Screenshot (72)
. Please I would need a code that would allow me show my current location, immediately the my screen renders. Note: I am developping for Android.

Reproducible Demo

@elkee2003 elkee2003 added the bug Something isn't working label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant