Skip to content
This repository was archived by the owner on Nov 3, 2019. It is now read-only.

Commit

Permalink
#1: Used global 'navigator.geolocation' and implement location update…
Browse files Browse the repository at this point in the history
… tracking
  • Loading branch information
jdoroy committed Jul 9, 2018
1 parent 0e5688d commit f03c5e4
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,67 @@
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { Constants, Location, Permissions } from 'expo';

import { StyleSheet, Text, View } from 'react-native';
import { Constants, Permissions } from 'expo';
export default class App extends Component {
state = {
location: null,
errorMessage: null,
};

componentWillMount() {
this._requestLocationPermission();
this._getLocationAsync();
}

componentDidMount() {
Location.watchPositionAsync(
this._updateLocation();
}

_getLocationAsync = async () => {
await navigator.geolocation.getCurrentPosition(
location => {
this.setState({
location,
});
},
({ message }) => {
this.setState({
errorMessage: message,
});
},
{
enableHighAccuracy: true,
},
location => {
this.setState(location)
}
);
}
// const location = await Location.getCurrentPositionAsync({});
// this.setState({ location });
};

_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
_requestLocationPermission = async () => {
const { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permission to access location was denied',
});
}
}

let location = await Location.getCurrentPositionAsync({});
this.setState({ location });
};
_updateLocation = () => {
navigator.geolocation.watchPosition(
location => {
this.setState({
location,
});
},
({ message }) => {
this.setState({
errorMessage: message,
});
},
{
enableHighAccuracy: true,
}
);
}

render() {
let text = 'Waiting..';
Expand Down

0 comments on commit f03c5e4

Please sign in to comment.