[ReactNative] geolocation method docs

This commit is contained in:
Spencer Ahrens 2015-04-24 16:10:46 -07:00
Родитель a1a15bda06
Коммит 68eb3e4906
2 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -50,7 +50,8 @@ var GeolocationExample = React.createClass({
componentDidMount: function() { componentDidMount: function() {
navigator.geolocation.getCurrentPosition( navigator.geolocation.getCurrentPosition(
(initialPosition) => this.setState({initialPosition}), (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.watchID = navigator.geolocation.watchPosition((lastPosition) => {
this.setState({lastPosition}); this.setState({lastPosition});

Просмотреть файл

@ -22,6 +22,12 @@ var subscriptions = [];
var updatesEnabled = false; var updatesEnabled = false;
type GeoOptions = {
timeout: number;
maximumAge: number;
enableHighAccuracy: bool;
}
/** /**
* You need to include the `NSLocationWhenInUseUsageDescription` key * You need to include the `NSLocationWhenInUseUsageDescription` key
* in Info.plist to enable geolocation. Geolocation is enabled by default * in Info.plist to enable geolocation. Geolocation is enabled by default
@ -32,10 +38,14 @@ var updatesEnabled = false;
*/ */
var Geolocation = { var Geolocation = {
/*
* Invokes the success callback once with the latest location info. Supported
* options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool)
*/
getCurrentPosition: function( getCurrentPosition: function(
geo_success: Function, geo_success: Function,
geo_error?: Function, geo_error?: Function,
geo_options?: Object geo_options?: GeoOptions
) { ) {
invariant( invariant(
typeof geo_success === 'function', 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) { if (!updatesEnabled) {
RCTLocationObserver.startObserving(options || {}); RCTLocationObserver.startObserving(options || {});
updatesEnabled = true; updatesEnabled = true;