React Native watchPosition not updating even after moving about 370m (android)

I am currently trying to get an android app to detect its position and then load the latitude and longitude into firebase every 10 seconds. Loading seems fine at the moment, but navigator.geolocation.watchPosition doesn't seem to update even after moving 370m, even though it should update every 10m.

I've tried testing both in an emulator, changing latitude and longitude, and also in real life on a 370 meters bike.

Oh, and yes, I have included permissions for the FINE location in the android manifest. I also tried testing to see if geolocation works at all and it seems to update if I emulate myself in London and then Oxford. Therefore, there is no problem in detecting massive changes in location, but not if the difference in location is only 370m, say one end of the road to the other.

Any help would be really appreciated !. Thanks in advance!

 import React, {
  Component,
} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  ScrollView
} from 'react-native';

let myDatas={
  timestamp:[],
  longitude:[],
  latitude:[],
};

export default class GeoLocation extends Component {
  constructor() {
    super();

    this.state = {
      latitude: null,
      longitude: null,
      timestamp: null,
      error: null,
    };
  }

  componentDidMount() {
var watchPositionID;


    watchPositionID = navigator.geolocation.watchPosition(
      (position) => {
        let now = new Date()
        myDatas.longitude.push(position.coords.longitude);
        myDatas.latitude.push(position.coords.latitude);
        myDatas.timestamp.push(now);
        this.setState({
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          timestamp: now,
          error: null,
        });
      },
      (error) => this.setState({error:error.message}),
      { enableHighAccuracy: true, timeout: 20000, maximumAge: 0, distanceFilter: 10},
      );


this.uploadTimer=setInterval(
  ()=>{
    uploadData(myDatas);
    myDatas={
      timestamp:[],
      longitude:[],
      latitude:[],
    };
  },10000
  )

}

componentWillUnmount() {
  navigator.geolocation.clearWatch(watchPositionID);
  this.uploadTimer && clearInterval(this.uploadTimer);
  this.timerpos && clearInterval(this.timerpos);
}



render() {
  return (
    <View>
    <Text>Latitude: {this.state.latitude}</Text>
    <Text>Longitude: {this.state.longitude}</Text>
    </View>
    );
}
}

      

+3
android react-native geolocation


source to share


No one has answered this question yet

Check out similar questions:

673
How to call a method after a delay in Android
586
What is the difference between React Native and React?
568
What is the difference between using a constructor and getInitialState in React / React Native?
566
Updating Eclipse with Android Development Tools v. 23
415
React Native android build failed. SDK location not found
360
Hide keyboard in responsive mode
303
How do I write in React Native?
147
Can I build Android apps with my family in mind?
2
React Native Geolocation Watchposition will not update in real time
1
React Native Geolocation watchPosition () documentation



All Articles
Loading...
X
Show
Funny
Dev
Pics