diff --git a/Examples/UIExplorer/GeolocationExample.js b/Examples/UIExplorer/GeolocationExample.js index c55bd351b..9bd744678 100644 --- a/Examples/UIExplorer/GeolocationExample.js +++ b/Examples/UIExplorer/GeolocationExample.js @@ -50,7 +50,8 @@ var GeolocationExample = React.createClass({ componentDidMount: function() { navigator.geolocation.getCurrentPosition( (initialPosition) => this.setState({initialPosition}), - (error) => console.error(error) + (error) => console.error(error), + {enableHighAccuracy: true, timeout: 100, maximumAge: 1000} ); this.watchID = navigator.geolocation.watchPosition((lastPosition) => { this.setState({lastPosition}); diff --git a/Libraries/Geolocation/Geolocation.js b/Libraries/Geolocation/Geolocation.js index 13fe40a23..fae309aef 100644 --- a/Libraries/Geolocation/Geolocation.js +++ b/Libraries/Geolocation/Geolocation.js @@ -22,6 +22,12 @@ var subscriptions = []; var updatesEnabled = false; +type GeoOptions = { + timeout: number; + maximumAge: number; + enableHighAccuracy: bool; +} + /** * You need to include the `NSLocationWhenInUseUsageDescription` key * in Info.plist to enable geolocation. Geolocation is enabled by default @@ -32,10 +38,14 @@ var updatesEnabled = false; */ var Geolocation = { + /* + * Invokes the success callback once with the latest location info. Supported + * options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool) + */ getCurrentPosition: function( geo_success: Function, geo_error?: Function, - geo_options?: Object + geo_options?: GeoOptions ) { invariant( typeof geo_success === 'function', @@ -48,7 +58,11 @@ var Geolocation = { ); }, - watchPosition: function(success: Function, error?: Function, options?: Object): number { + /* + * Invokes the success callback whenever the location changes. Supported + * options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool) + */ + watchPosition: function(success: Function, error?: Function, options?: GeoOptions): number { if (!updatesEnabled) { RCTLocationObserver.startObserving(options || {}); updatesEnabled = true;