Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(location-accuracy): add location accuracy plugin #583

Merged
merged 1 commit into from
Sep 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { IsDebug } from './plugins/is-debug';
import { Keyboard } from './plugins/keyboard';
import { LaunchNavigator } from './plugins/launchnavigator';
import { LocalNotifications } from './plugins/localnotifications';
import { LocationAccuracy } from './plugins/location-accuracy';
import { MediaCapture } from './plugins/media-capture';
import { NativeAudio } from './plugins/native-audio';
import { NativePageTransitions } from './plugins/native-page-transitions';
Expand Down Expand Up @@ -98,7 +99,7 @@ import { ThreeDeeTouch } from './plugins/3dtouch';
import { Toast } from './plugins/toast';
import { TouchID } from './plugins/touchid';
import { TextToSpeech } from './plugins/text-to-speech';
import {ThemableBrowser} from './plugins/themable-browser';
import { ThemableBrowser } from './plugins/themable-browser';
import { TwitterConnect } from './plugins/twitter-connect';
import { Vibration } from './plugins/vibration';
import { VideoEditor } from './plugins/video-editor';
Expand Down Expand Up @@ -188,6 +189,7 @@ Insomnia,
Instagram,
IsDebug,
Keyboard,
LocationAccuracy,
MusicControls,
NativeAudio,
NativeStorage,
Expand Down Expand Up @@ -278,6 +280,7 @@ window['IonicNative'] = {
Keyboard,
LaunchNavigator,
LocalNotifications,
LocationAccuracy,
Market,
MediaCapture,
MediaPlugin,
Expand Down
66 changes: 66 additions & 0 deletions src/plugins/location-accuracy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {Plugin, Cordova} from './plugin';
/**
* @name LocationAccuracy
* @description
* This Cordova/Phonegap plugin for Android and iOS to request enabling/changing of Location Services by triggering a native dialog from within the app, avoiding the need for the user to leave your app to change location settings manually.
*
* @usage
* ```
* import { LocationAccuracy } from 'ionic-native';
*
* LocationAccuracy.canRequest().then((canRequest: boolean) => {
*
* if(canRequest) {
* // the accuracy option will be ignored by iOS
* LocationAccuracy.request(LocaitonAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(
* () => console.log('Request successful'),
* error => console.log('Error requesting location permissions', error)
* );
* }
*
* });
*
* ```
*/
@Plugin({
plugin: 'cordova-plugin-request-location-accuracy',
pluginRef: 'cordova.plugins.locationAccuracy',
repo: 'https://github.com/dpa99c/cordova-plugin-request-location-accuracy'
})
export class LocationAccuracy {
/**
* Indicates if you can request accurate location
* @returns {Promise<boolean>} Returns a promise that resovles with a boolean that indicates if you can request accurate location
*/
@Cordova()
static canRequest(): Promise<boolean> { return; }

/**
* Indicates if a request is currently in progress
* @returns {Promise<boolean>} Returns a promise that resolves with a boolean that indicates if a request is currently in progress
*/
@Cordova()
static isRequesting(): Promise<boolean> { return; }

/**
* Requests accurate location
* @returns {Promise<any>} Returns a promise that resolves on success and rejects if an error occurred
*/
@Cordova({ callbackOrder: 'reverse' })
static request(accuracy: string): Promise<any> { return; }

static REQUEST_PRIORITY_NO_POWER = 0;
static REQUEST_PRIORITY_LOW_POWER = 1;
static REQUEST_PRIORITY_BALANCED_POWER_ACCURACY = 2;
static REQUEST_PRIORITY_HIGH_ACCURACY = 3;
static SUCCESS_SETTINGS_SATISFIED = 0;
static SUCCESS_USER_AGREED = 1;
static ERROR_ALREADY_REQUESTING = -1;
static ERROR_INVALID_ACTION = 0;
static ERROR_INVALID_ACCURACY = 1;
static ERROR_EXCEPTION = 1;
static ERROR_CANNOT_CHANGE_ACCURACY = 3;
static ERROR_USER_DISAGREED = 4;
static ERROR_GOOGLE_API_CONNECTION_FAILED = 4;

}