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

RMET-3900 :: bridge :: add getCurrentPosition wrapper for both capacitor and cordova #1

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 1 addition & 2 deletions packages/android-lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.outsystems.plugins.osgeolocation">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
20 changes: 18 additions & 2 deletions packages/capacitor-plugin/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ import { WebPlugin } from '@capacitor/core';
import type { CallbackID, ClearWatchOptions, GeolocationPluginPermissions, IGeolocationPlugin, PermissionStatus, Position, PositionOptions, WatchPositionCallback } from './definitions';

export class GeolocationPluginWeb extends WebPlugin implements IGeolocationPlugin {
getCurrentPosition(options?: PositionOptions): Promise<Position> {
throw new Error('Method not implemented.');
async getCurrentPosition(options?: PositionOptions): Promise<Position> {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
pos => {
resolve(pos);
},
err => {
reject(err);
},
{
enableHighAccuracy: false,
timeout: 10000,
maximumAge: 0,
...options,
OS-pedrogustavobilro marked this conversation as resolved.
Show resolved Hide resolved
},
);
});
}

watchPosition(options: PositionOptions, callback: WatchPositionCallback): Promise<CallbackID> {
throw new Error('Method not implemented.');
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cordova-plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ node_modules/

# Generated by Cordova
/plugins/
/platforms/
dist/
/platforms/
4 changes: 4 additions & 0 deletions packages/cordova-plugin/dist/defaults.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ClearWatchOptions, PositionOptions } from './definitions';

export declare const PositionOptionsDefault: PositionOptions;
export declare const ClearWatchOptionsDefault: ClearWatchOptions;
130 changes: 130 additions & 0 deletions packages/cordova-plugin/dist/definitions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
export type PluginError = {
code: string;
message: string;
};
export type OSGLOCPosition = {
timestamp: number;
latitude: number;
longitude: number;
accuracy: number;
altitude: number | null;
speed: number | null;
heading: number | null;
altitudeAccuracy: number | null;
};
export type LegacyOSPosition = {
timestamp: number;
latitude: number;
longitude: number;
accuracy: number;
altitudeAccuracy: number | null | undefined;
altitude: number | null;
velocity: number | null;
heading: number | null;
};
Comment on lines +5 to +24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both? They are identical so I was wondering if we could reuse one of them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed!

export type PositionOptions = {
/**
* High accuracy mode (such as GPS, if available)
*
* On Android 12+ devices it will be ignored if users didn't grant
* ACCESS_FINE_LOCATION permissions (can be checked with location alias).
*
* @default false
* @since 1.0.0
*/
enableHighAccuracy?: boolean;
/**
* The maximum wait time in milliseconds for location updates.
*
* In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition.
*
* @default 10000
* @since 1.0.0
*/
timeout?: number;
/**
* The maximum age in milliseconds of a possible cached position that is acceptable to return
*
* @default 0
* @since 1.0.0
*/
maximumAge?: number;
/**
* The minumum update interval for location updates.
*
* If location updates are available faster than this interval then an update
* will only occur if the minimum update interval has expired since the last location update.
*
* This parameter is only available for Android. It has no effect on iOS or Web platforms.
*
* @default 5000
* @since 6.1.0
*/
minimumUpdateInterval?: number;
/**
* @deprecate since 1.0.0
* */
id?: ReturnType<typeof setTimeout>;
};
export type ClearWatchOptions = {
id: string;
};
export type Position = {
/**
* Creation timestamp for coords
*
* @since 1.0.0
*/
timestamp: number;
/**
* The GPS coordinates along with the accuracy of the data
*
* @since 1.0.0
*/
coords: {
/**
* Latitude in decimal degrees
*
* @since 1.0.0
*/
latitude: number;
/**
* longitude in decimal degrees
*
* @since 1.0.0
*/
longitude: number;
/**
* Accuracy level of the latitude and longitude coordinates in meters
*
* @since 1.0.0
*/
accuracy: number;
/**
* Accuracy level of the altitude coordinate in meters, if available.
*
* Available on all iOS versions and on Android 8.0+.
*
* @since 1.0.0
*/
altitudeAccuracy: number | null | undefined;
/**
* The altitude the user is at (if available)
*
* @since 1.0.0
*/
altitude: number | null;
/**
* The speed the user is traveling (if available)
*
* @since 1.0.0
*/
speed: number | null;
/**
* The heading the user is facing (if available)
*
* @since 1.0.0
*/
heading: number | null;
};
};
2 changes: 2 additions & 0 deletions packages/cordova-plugin/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './web';
export * from './definitions';
90 changes: 90 additions & 0 deletions packages/cordova-plugin/dist/plugin.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"use strict";
const cordova = require("cordova");
function s(t) {
t.CapacitorUtils.Synapse = new Proxy(
{},
{
get(e, o) {
return new Proxy({}, {
get(w, r) {
return (c, p, n) => {
const i = t.Capacitor.Plugins[o];
if (i === void 0) {
n(new Error(`Capacitor plugin ${o} not found`));
return;
}
if (typeof i[r] != "function") {
n(new Error(`Method ${r} not found in Capacitor plugin ${o}`));
return;
}
(async () => {
try {
const a = await i[r](c);
p(a);
} catch (a) {
n(a);
}
})();
};
}
});
}
}
);
}
function u(t) {
t.CapacitorUtils.Synapse = new Proxy(
{},
{
get(e, o) {
return t.cordova.plugins[o];
}
}
);
}
function y() {
window.CapacitorUtils = window.CapacitorUtils || {}, window.Capacitor !== void 0 ? s(window) : window.cordova !== void 0 && u(window);
}
const PositionOptionsDefault = {
enableHighAccuracy: false,
timeout: 1e3,
maximumAge: 0,
minimumUpdateInterval: 5e3
};
const ClearWatchOptionsDefault = {
id: "-1"
};
var exec = cordova.require("cordova/exec");
function getCurrentPosition(options, success, error) {
options = { ...PositionOptionsDefault, ...options };
let convertOnSuccess = (position) => {
let convertedPosition = {
coords: {
latitude: position.latitude,
longitude: position.longitude,
altitude: position.altitude,
accuracy: position.accuracy,
heading: position.heading,
speed: position.speed,
altitudeAccuracy: position.accuracy
},
timestamp: position.timestamp
};
success(convertedPosition);
};
exec(convertOnSuccess, error, "OSGeolocation", "getCurrentPosition", [options]);
}
function watchPosition(options, success, error) {
options = options || PositionOptionsDefault;
exec(success, error, "OSGeolocation", "watchPosition", [options]);
}
function clearWatch(options, success, error) {
options = options || ClearWatchOptionsDefault;
exec(success, error, "OSGeolocation", "clearWatch", [options]);
}
module.exports = {
getCurrentPosition,
watchPosition,
clearWatch
};
y();
93 changes: 93 additions & 0 deletions packages/cordova-plugin/dist/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
(function(global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? factory(require("cordova")) : typeof define === "function" && define.amd ? define(["cordova"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.cordova));
})(this, function(cordova) {
"use strict";
function s(t) {
t.CapacitorUtils.Synapse = new Proxy(
{},
{
get(e, o) {
return new Proxy({}, {
get(w, r) {
return (c, p, n) => {
const i = t.Capacitor.Plugins[o];
if (i === void 0) {
n(new Error(`Capacitor plugin ${o} not found`));
return;
}
if (typeof i[r] != "function") {
n(new Error(`Method ${r} not found in Capacitor plugin ${o}`));
return;
}
(async () => {
try {
const a = await i[r](c);
p(a);
} catch (a) {
n(a);
}
})();
};
}
});
}
}
);
}
function u(t) {
t.CapacitorUtils.Synapse = new Proxy(
{},
{
get(e, o) {
return t.cordova.plugins[o];
}
}
);
}
function y() {
window.CapacitorUtils = window.CapacitorUtils || {}, window.Capacitor !== void 0 ? s(window) : window.cordova !== void 0 && u(window);
}
const PositionOptionsDefault = {
enableHighAccuracy: false,
timeout: 1e3,
maximumAge: 0,
minimumUpdateInterval: 5e3
};
const ClearWatchOptionsDefault = {
id: "-1"
};
var exec = cordova.require("cordova/exec");
function getCurrentPosition(options, success, error) {
options = { ...PositionOptionsDefault, ...options };
let convertOnSuccess = (position) => {
let convertedPosition = {
coords: {
latitude: position.latitude,
longitude: position.longitude,
altitude: position.altitude,
accuracy: position.accuracy,
heading: position.heading,
speed: position.speed,
altitudeAccuracy: position.accuracy
},
timestamp: position.timestamp
};
success(convertedPosition);
};
exec(convertOnSuccess, error, "OSGeolocation", "getCurrentPosition", [options]);
}
function watchPosition(options, success, error) {
options = options || PositionOptionsDefault;
exec(success, error, "OSGeolocation", "watchPosition", [options]);
}
function clearWatch(options, success, error) {
options = options || ClearWatchOptionsDefault;
exec(success, error, "OSGeolocation", "clearWatch", [options]);
}
module.exports = {
getCurrentPosition,
watchPosition,
clearWatch
};
y();
});
Loading