I use navigator.geolocation.watchPosition in my own project to draw the path on the map while the user is moving. I noticed that the return frequency is pretty low for this function. I taught that it was a frequency, at least when I tested using the iOS emulator and the "freeway drive" mode in the gps emulator. Now, when I tested the "city mileage", I see that the frequency of position return does not depend on a certain time interval, but instead on a distance ... The function returns its position every 100 meters regardless of how long it took to the situation has changed a lot.
Why is that? Is this expected behavior? I donβt know if this is connected with the iOS emulator or with my code, but I would really like the position to be more accurate, I want it to return as often as possible.
componentDidMount() { const { region } = this.state; navigator.geolocation.getCurrentPosition( (position) => { this.setState({position}); }, (error) => alert(JSON.stringify(error)), {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000} ); this.watchID = navigator.geolocation.watchPosition((lastPosition) => { var { distanceTotal, record } = this.state; this.setState({lastPosition}); if(record) { var newLatLng = {latitude:lastPosition.coords.latitude, longitude: lastPosition.coords.longitude}; this.setState({ track: this.state.track.concat([newLatLng]) }); this.setState({ distanceTotal: (distanceTotal + this.calcDistance(newLatLng)) }); this.setState({ prevLatLng: newLatLng }); } }, (error) => alert(JSON.stringify(error)), {enableHighAccuracy: true, timeout: 20000, maximumAge: 0}); }
theva source share