Introducing the Geolocation API
React Native provides an easy-to-use abstraction over the native Geolocation APIs. It follows the MDN (Mozilla Developer Network) specification, which recommends the following geolocation interface:
navigator.geolocation.getCurrentPosition(success, error, options)
This method asynchronously
asks for the device's current location and will call the success
callback with a Position
object if it is successful and the error
callback if it fails (usually, due to misconfigured permissions in your app or the user explicitly rejecting the request to allow your app to know their location). The options
argument allows you to request higher position accuracy, define how long you're willing to wait for a response, and specify the maximum age of cached data that you're willing to accept:
navigator.geolocation.watchPosition(success, error, options)
This function enables you to register a function that will be called each time the position changes. This function...