Comments (6)
You have a binding: setDistance
is not bound to your class instance, so this.setState()
won't work there (as it there is no this
in it).
Use one of these 5 suggested approaches to solve it. My preference goes out to number 5 “Arrow Function in Class Property“:
class Example extends React.Component {
// By using an Arrow Function, the function will be bound to the execution context from which it is called (“lexical this”)
setDistance = (distance,duration_in_traffic) => {
this.setState({distance:parseFloat(distance),durationInTraffic:parseInt(duration_in_traffic)});
}
render() {
// ...
}
}
See Javascript ES6 — Arrow Functions and Lexical this
for more info.
from react-native-maps-directions.
I have tried and it should not be related to this issue since it can successfully execute the code inside setDistance, but somehow it will drive onReady to infinity loop when I call the function or this.setState().
from react-native-maps-directions.
Ok, think I see it now: setState() will trigger a re-render, thus re-rendering MapViewDirections
. Normally a re-render with the same data won't happen, but I'll look further into it to be sure …
from react-native-maps-directions.
The problem is in this line:
if ((nextProps.origin != this.props.origin) || (nextProps.destination != this.props.destination) || !isEqual(nextProps.waypoints, this.props.waypoints)) {
You should not compare arrays in JS directly, because two arrays are always not equal. You should compare route values. Use isEqual instead of !== to fix this issue.
from react-native-maps-directions.
Good point @sidious18. Working and testing a fix right now.
from react-native-maps-directions.
It took a bit longer than expected, but couldn't trigger this one myself at first. The “culprit” was the fact that I used an array holding all coordinates in my state. This then resulted in the fact that the references remained the same all the time, even after a re-render.
In contrast: the example above creates a new object on every render. Even though react-native-maps-directions
can now catch this, I'd advise against this use.
Thanks to all involved for their input :)
from react-native-maps-directions.
Related Issues (20)
- Fix for timePrecison
- Check render method for 'MapViewDirections' HOT 3
- Render Pre-existing JSON Directions Data in Map HOT 5
- How is this library showing the Steps? HOT 1
- App crashes on real device (iOS only) for some routes with precision={'high'} HOT 2
- how to get get toll info
- Call Directions Api only if new location is not in already made polyline. HOT 2
- Using MapKit instead of Google for directions? HOT 3
- App crashes when GPS is not enabled HOT 1
- How to draw route according to vehicle type
- LinearGradient for the direction color
- I see nothing on my mobile screen(android emulator) HOT 1
- onReady event is firing at the very start.
- Not Supported In React Native 0.63.4
- Any way to get bounds in the data returning from onReady method of MapViewDirections HOT 1
- onReady callback is changing automatically to distance : 0 duration : 0 from its given pickup and destination HOT 1
- Direction line flickering HOT 1
- API ERROR HOT 1
- onReady result json data and navigation
- Please add ability to pass time of departure to timePrecision props
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-maps-directions.