How to Add Geolocation to a React App
Subscribe to my email list now at http://jauyeung.net/subscribe/ .
Follow me on Twitter at https://twitter.com/AuMayeung
Many apps want to get data based on location. This is where the HTML Geolocation API comes in. You can use it easily to get the location of the current device via the Internet.
To get the location of the device the browser is running with plain JavaScript, we write:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getPosition);
}