score:1

Accepted answer

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
}

score:-1

try using your fetch like this:

return fetch('https://***&geofilter.distance='+this.state.region.latitude+'%2c2.3883402698750875%2c2000')

score:1

you are storing your latitude in state so you need to call it as this.state.region.latitude

return fetch('https://***&geofilter.distance='+this.state.region.latitude+'%2c2.3883402698750875%2c2000')

Related Query

More Query from same tag