Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with React Native

You're reading from   Getting Started with React Native Learn to build modern native iOS and Android applications using JavaScript and the incredible power of React

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781785885181
Length 172 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image