Skip to content

Instantly share code, notes, and snippets.

@vinodsobale
Created December 11, 2018 05:15
Show Gist options
  • Save vinodsobale/9dca985be9a833fd28bc2611a4f906fe to your computer and use it in GitHub Desktop.
Save vinodsobale/9dca985be9a833fd28bc2611a4f906fe to your computer and use it in GitHub Desktop.
geolocation
getLocation() {
this.setState((prevState, props) => {
return {
fetchingLocation: true
};
});
getGeoLocation()
.then(position => {
this.setState((prevState, props) => {
return {
fetchingLocation: false,
fetchingPoasterBoards: true
};
});
const lat = position.coords.latitude,
lang = position.coords.longitude;
feedApi
.getPoasterBoards(lat, lang)
.then(json => {
this.setState((prevState, props) => {
return {
poasterBoards: json.data,
fetchingPoasterBoards: false
};
});
})
.catch(err => {
console.log(err);
this.setState((prevState, props) => {
return {
fetchingPoasterBoards: false
};
});
});
})
.catch(error => {
var msg = null;
switch (error.code) {
case error.PERMISSION_DENIED:
msg = "User denied the request for Geolocation.";
break;
case error.POSITION_UNAVAILABLE:
msg = "Location information is unavailable.";
break;
case error.TIMEOUT:
msg = "The request to get user location timed out.";
break;
case error.UNKNOWN_ERROR:
msg = "An unknown error occurred.";
break;
}
alert(msg);
this.setState((prevState, props) => {
return {
fetchingLocation: false,
fetchingPoasterBoards: false
};
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment