Q:

How can I pass variable in my fetch request

I'm using react native and try to understand some examples. 
I've got a problem
I'm trying to pass latitude in my fetch but I've got a problem who say me "latitude" don't exist
class App extends React. Component {
constructor() {
super();
this.state = {
  region: {
    latitude: LATITUDE,
      longitude: LONGITUDE,
      latitudeDelta: LATITUDE_DELTA,
      longitudeDelta: LONGITUDE_DELTA,
  },
  markers: [],
  loaded: false
}

}

componentDidMount() {
navigator.geolocation.getCurrentPosition(
  (position) => {
    console.log(position);
    this.setState({
      region: {
        latitude: position.coords.latitude,
        longitude: position.coords.longitude,
        latitudeDelta: LATITUDE_DELTA,
        longitudeDelta: LONGITUDE_DELTA,
      }
    });
  },
  (error) => this.setState({ error: error.message }),
  { enableHighAccuracy: false, timeout: 200000, maximumAge: 1000 },
  );
  this.getLocations()
}

getLocations(){
  return fetch('https://***&geofilter.distance='+latitude+'%2C2.3883402698750875%2C2000') //here
  .then(response => response.json())
  .then(responseData =>{
    var markers = [];

Can you help me, thanks :)

A:

In getLocations, you're trying to use a latitude variable, but there is none in scope there.  You may have wanted this.state.region.latitude. 
If you're trying to use this.state.region.latitude, though, you need to move your call to getLocations in componentDidMount so that it's inside a state change completion handler:
componentDidMount() {
  navigator.geolocation.getCurrentPosition(
    (position) => {
      console.log(position);
      this.setState({
        region: {
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          latitudeDelta: LATITUDE_DELTA,
          longitudeDelta: LONGITUDE_DELTA,
        }
      },
      () => {                   // ***
        this.getLocations();    // ***
      });                       // ***
    },
    (error) => this.setState({ error: error.message }),
    { enableHighAccuracy: false, timeout: 200000, maximumAge: 1000 },
  );
  // *** Not here
}

