score:1
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')
Source: stackoverflow.com
Related Query
- How can I pass variable in my fetch request
- React how can you pass a variable to a get request
- How can I pass a variable from 'outside' to a react app?
- How can I get rid of a URL in a fetch (to use kind of a variable instead)?
- How can I pass a variable between two components in React?
- How can I pass a locally created function and variable as props in a component?
- How to call a react hook fetch request in a functional component to access data then pass to a class component to map?
- How to pass variable as a parameter in api call fetch in javascript, react native
- React: How can you pass a "not defined" variable as a prop to a component?
- How can I pass entire react state with post request
- How do pass string into variable using the request api inside my react component?
- How to pass variable when dispatching fetch function in react component?
- How can i store api response in variable and pass it to react popup video player
- How can i update fetch request in reactjs
- How can I do to pass variable throught the modals?
- How can I pass a value in a variable to a React component
- How can I pass a variable in a form to to a onclick function in React.js?
- How can i seperate my fetch request to another file in react js
- How can I fetch data from an array of objects, pass it through an API end point to .fetch() the needed object value using React?
- How can I pass the data from a POST request to my global state with Redux?
- How can I pass a URL querystring variable dynamically to a composed graphql query in react?
- How can i access and pass a variable value defined in return method and pass it to another component in reactjs?
- How to pass a variable from a post request to a function that takes params as string or array of string in Node.js?
- How can I loop through the zone id and pass each zoneId to uosId to make an API request each
- I want to pass my fetch results to setState. When I console.log(setUserApartment) it doesn't show the data from foundApartment. How can I setState?
- How can I pass css variable to media queries in Javascript Object?
- How can I pass useQuery variable from component prop?
- Fetch request method Get.. How i can get response with query params?
- How can I pass a variable from my post to my get?
- How can I limit and insert conditions on results returned from API fetch request after using map
More Query from same tag
- How to resolve " Cannot read property 'map' of undefined" error in React Js
- Keeping Client State Up-To-Date In Reagent / Clojurescript
- Correct way to pass functions to handlers in 'dumb' components in React
- React-router component not routing where I want
- React google login does not work with axios
- Apply button 'Active' styles on keypress in React
- Remove object property based on array values
- How to prevent empty messages from being sent
- filter object array with other object array - React Typescript
- Mapping API info to React Component
- Export .scss to build folder?
- How to use local webfont in imported sass file?
- Using progress handler when uploading files to AWS S3 with React
- How can I stop history go back if we are loading React app on a new page?
- ReactJS does not re-loads my updated component when separate links are clicked from the navbar
- Flow-typing higher-order components for props injection (while preserving the optionality of defaultProps)
- Using React, findDOMNode is deprecated in StrictMode is thrown as a warning when using react-transition-group
- JSX element type 'Element[]' is not a constructor function for JSX elements?
- Type a prop to accept either one interface or another interface
- Trying to retrieve an avatar image from an API but receiving an error of avatar not defined
- Prevent Reload in React Native WebView
- componentWillRecieveProps vs getDerivedStateFromProps
- Why componentDidMount does not get fired?
- Jest: Testing Toolbar Menu component doesn't simulate click event
- How do I pass the "img" object to an onload event handler in ReactJS JSX?
- Monaco editor - Pre-populate find control with text
- Reload Live Image without Flickering in React
- Getting 'Object is of type unknown' in createAsyncThunk function after using Typescript and Redux Toolkit
- How to mock react custom hook return value as a module with Jest
- Building a select option dropdown: Objects are not valid as a React child