Location is not working.?

Hi. The following line has incorrect syntax:

    console.log(hi how are you)

It should be:

    console.log("hi how are you")

Also, the const { status } = await Permissions.getAsync(Permissions.LOCATION); call is returning “undetermined” for me and it does not ask me to grant the LOCATION permission. You should call askAsync like in the example from the documentation:

async function getLocationAsync() {
  // permissions returns only for location permissions on iOS and under certain conditions, see Permissions.LOCATION
  const { status, permissions } = await Permissions.askAsync(Permissions.LOCATION);
  if (status === 'granted') {
    return Location.getCurrentPositionAsync({ enableHighAccuracy: true });
  } else {
    throw new Error('Location permission not granted');
  }
}

What is this?

it is just for allowing google maps or nothing it is not the problem

can you copy and paste my code in your slack n check it once . it will be very helpful

Are you sure it’s not supposed to be PROVIDER_GOOGLE?

Also, please edit your post to mark your code as code.

```
code
here
```

Otherwise the forum does not format it correctly and messes up the quotes etc. so it’s not possible to just copy and paste it into a snack.

yes i am . n even if you remove this line still the code is not working the poblem is in the _getlocation method may be . but i think i have written it correctly

The company name is spelt with a “G”, not a “C”.

here is my code

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import  * as Expo from 'expo';
import MapView ,{PROVIDER_COOGLE} from 'react-native-maps'
import  {Permissions , Location } from 'expo';

export default class App extends React.Component {

    state = {
      location: null
    }

  _getLocation = async() => {
     console.log("console is coming .............let s see ")
    const {status ,permission } = await Permissions.getAsync(Permissions.LOCATION)
    if(status !== 'granted'){
      console.error('why this console is not coming ......................')
      return
    }
    let location =  await Location.getCurrentPositionAsync({})
    this.setState({ location })
    console.log("nor the console.log of this location.......")
    console.log(location)
  }

  

  componentDidMount() {
    this._getLocation()
  }

  render() {

    if(!this.state.location){
      return (<Text> hello it will not work </Text>)
    }
    return (
      <MapView style={{flex: 1}}
          initialRegion={{
          latitude: this.state.location.coords.latitude,
          longitude: this.state.location.coords.longitude,
          latitudeDelta: 0.0922,
          longitudeDelta: 0.0421,
    }}
    /> 
    );
  }
}

where u r talking about . not i changed my above code .please check it once .it will be very kind of you

I agree it’s probably not the problem, but you have spelt “google” incorrectly as “coogle” in “PROVIDER_COOGLE”.

oh , thank u i changed that but stilll dear there’s problem and i dont know what it is

now also this is not working in my snack . i am not gettting any location plz see my code also

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import  * as Expo from 'expo';
import MapView ,{PROVIDER_GOOGLE} from 'react-native-maps'
import  {Permissions , Location } from 'expo';

export default class App extends React.Component {

    state = {
      location: null
    }

  _getLocation = async() => {
     console.log("console is coming .............let s see  how are you")
    const {status ,permission } = await Permissions.getAsync(Permissions.LOCATION)
    console.log("let see this line of code")
    if(status !== 'granted'){
      console.error('why this console is not coming ......................')
      return console.error('why this console is not coming ......................')
    }
    let location =  await Location.getCurrentPositionAsync({})
    this.setState({ location })
    console.log("nor the console.log of this location.......")
   return console.log(location)
  }

  

  componentDidMount() {
    this._getLocation()
  }

  render() {

    if(!this.state.location){
      return (<Text> hello it will not work </Text>)
    }
    return (
      <MapView style={{flex: 1}}
          initialRegion={{
          latitude: this.state.location.coords.latitude,
          longitude: this.state.location.coords.longitude,
          latitudeDelta: 0.0922,
          longitudeDelta: 0.0421,
    }}
    /> 
    );
  }
}

Instead of this:

import  {Permissions , Location } from 'expo';

you need this:

import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';

See here and here.

I’ve updated your code based on the documentation:

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import * as Expo from 'expo';
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';

export default class App extends React.Component {
  state = {
    location: null,
  };

  _getLocationAsync = async () => {
    let { status } = await Permissions.askAsync(Permissions.LOCATION);
    if (status !== 'granted') {
      this.setState({
        errorMessage: 'Permission to access location was denied',
      });
    }

    let location = await Location.getCurrentPositionAsync({});
    this.setState({ location });
  };

  componentWillMount() {
    this._getLocationAsync();
  }

  render() {
    if (!this.state.location) {
      return (
        <View
          style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
          <Text> hello it will not work </Text>
        </View>
      );
    }
    return (
      /*
        <View
          style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
          <Text>{JSON.stringify(this.state)}</Text>
        </View>
      */
      <MapView
        style={{ flex: 1 }}
        initialRegion={{
          latitude: this.state.location.coords.latitude,
          longitude: this.state.location.coords.longitude,
          latitudeDelta: 0.0922,
          longitudeDelta: 0.0421,
        }}
      />
    );
  }
}