Initial Postion bases on geolocation

Hi, Everyone,
I’m not sure if I should write this question on here.

On my app, I did this on render:

<MapView 
          style = {styles.mapView}
          initialRegion={this.state.currentRegion}
          showsUserLocation = {true}
          ))}

and I have this to get user’s current position:

componentDidMount: function() {
    navigator.geolocation.getCurrentPosition(
      (position) => {
       console.log(position);
        this.setState({currentRegion: {
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          latitudeDelta: LATITUDE_DELTA,
          longitudeDelta: LONGITUDE_DELTA,
        }});
      },
      (error) => alert(error.message),
      {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
    );
    this.watchID = navigator.geolocation.watchPosition((position) => {
       console.log(position);
      this.setState({currentRegion: {
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          latitudeDelta: LATITUDE_DELTA,
          longitudeDelta: LONGITUDE_DELTA,
        }});

    })

But with this, It’s didn’t auto move to current region on Android, but on iOS it’ll move to current region when open that page.

Thanks.

4 thoughts on “Initial Postion bases on geolocation

Comments are closed.