title: How do I continually update my gps coordinates in react native?
body: <p>Im creating a react native app that has built in methods for grabbing my longitude and latitude coordinates. I'm using an android for this.</p>
  
  <p>I't works fairly randomly, even though i am using a setInterval. Sometimes it only responds when I'm moving around, and sometimes it will update properly even when I'm not moving.</p>
  
  <pre><code>import React, { Component } from 'react';
  import { View, Text } from 'react-native';
  
  
  class Geolocation extends Component {
    constructor(props) {
      super(props);
  
     this.state = {
        latitude: null,
        longitude: null,
        error: null
      };
  
     setInterval(this.location.bind(this),3000)
    }
  
   location(){
      this.watchId = navigator.geolocation.getCurrentPosition(
        (position) =&gt; {
          let obj = {
            latitude: position.coords.latitude,
            longitude: position.coords.longitude,
            error: null
          }
          this.setState(obj);
        },
        (error) =&gt; this.setState({ error: error.message }),
        { enableHighAccuracy: true, timeout: 200000, maximumAge: 1000},
      );
    }
  
   componentDidMount() {
      this.location()
    }
  
   componentWillUnmount() {
      navigator.geolocation.clearWatch(this.watchId);
    }
  
   render() {
      return (
  
               &lt;View style={{ position: 'relative', top: 70, flexGrow: 1, 
  alignItems: 'center', justifyContent: 'center' }}&gt;
                &lt;Text&gt;Latitude: {this.state.latitude}&lt;/Text&gt;
                &lt;Text&gt;Longitude: {this.state.longitude}&lt;/Text&gt;
                  {this.state.error ? &lt;Text&gt;Error: {this.state.error}&lt;/Text&gt; : null}
               &lt;/View&gt;
  
      );
    }
  }
  
  export default Geolocation;
  </code></pre>
  
  <p>Again my problem is the location doesn't update properly, I've tried on both wifi and my phones 4g data and no change.</p>
  
  <p>How do I make the location coordinates update regularly?</p>
  
  <p>Any help is greatly appreciated!</p>