npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aldegad/capacitor-geolocation

v0.1.0

Published

This is a capacitor plugin, let you receive geolocation updates either forground and background. Android and iOS platforms are suppoerted.

Downloads

16

Readme

@aldegad/capacitor-geolocation

This is a capacitor plugin, let you receive geolocation updates either forground and background. Android and iOS platforms are suppoerted.

Install

npm install @aldegad/capacitor-geolocation
npx cap sync

Quick Example

typescript


import { Geolocation, GeolocationAlert, GeolocationConnect } from '@aldegad/capacitor-geolocation';

async startLocationUpdates() {
    const { state } = await Geolocation.requestPermission();

    if(state !== 'granted') return;

    Geolocation.startLocationUpdates(null, ({latitude, longitude}) => {
        console.log("location updates", `${latitude}/${longitude}`);
    });
}
stopLocationUpdates() {
    Geolocation.startLocationUpdates();
}

API

requestPermission(...)

requestPermission(options?: GeolocationPermissionOptions | undefined) => Promise<{ state: GeolocationPermissionState; }>

Request and check geolocation permissions. You can define alert cotext.

| Param | Type | | ------------- | ------------------------------------------------------------------------------------- | | options | GeolocationPermissionOptions |

Returns: Promise<{ state: GeolocationPermissionState; }>

Since: 0.0.1


startLocationUpdates(...)

startLocationUpdates(options?: GeololocationUpdatesOptions | undefined, callback?: GeolocationUpdatesCallback | undefined) => Promise<void>

Start location updates.

| Param | Type | | -------------- | ----------------------------------------------------------------------------------- | | options | GeololocationUpdatesOptions | | callback | GeolocationUpdatesCallback |

Since: 0.0.1


stopLocationUpdates()

stopLocationUpdates() => Promise<void>

Stop location updates.

Since: 0.0.1


Interfaces

GeolocationPermissionOptions

Geolocation permission options.

| Prop | Type | Description | Since | | ----------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----- | | promptAlert | GeolocationAlertOptions | Android only. If user ignore geolocation permission, notice why this application needs geolocation permissions. | 0.0.1 | | deniedAlert | GeolocationAlertOptions | If user denied geolocation permission, notice why this application needs geolocation permissions and tells how to reset permissions. | 0.0.1 |

GeolocationAlertOptions

Geolocation alert options.

| Prop | Type | Description | Since | | ---------------- | ------------------- | ----------------- | ----- | | header | string | Alert header | 0.0.1 | | message | string | Alert message | 0.0.1 | | okText | string | Alert ok text | 0.0.1 | | cancelText | string | Alert cancel text | 0.0.1 |

GeololocationUpdatesOptions

Geolocation updates options.

| Prop | Type | Description | Default | Since | | ------------------ | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------- | ----- | | background | boolean | Toggle background geolocation enable or not. | true | 0.0.1 | | notification | GeolocationNotificationOptions | This is Android forground notification option. If you need to run background geolocation on Android, you must define notification. | | 0.0.1 | | connect | GeolocationConnectOptions | After location updates, upload data to server. It uses multipart-formdata. | Nothing to do is default. | 0.0.1 |

GeolocationNotificationOptions

This is Android forground notification module. If you need to run background Geolocation on Android, you must define notification.

| Prop | Type | Description | Default | Since | | ----------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | ----- | | channelID | string | Android notification channel id | "LOCATION_SERVICE_CHANNEL" | 0.0.1 | | channelName | string | Android notification cannel name | "Geolocation tracking notification" | 0.0.1 | | header | string | Android notification header | "Geolocation tracker" | 0.0.1 | | message | string | Android notification message | "Geolocation tracking now." | 0.0.1 | | icon | string | Android notification icon. Icon's path should be in android/app/res folder. Do not use image mine-type like .png, .jpeg etc. | "mipmap/ic_launcher" | 0.0.1 |

GeolocationConnectOptions

After location updates, upload data to server. multipart-formdata

| Prop | Type | Description | Default | Since | | ---------- | -------------------------------------------------- | ------------------------------------------------------------------------------------- | ----------------- | ----- | | url | string | Update url | null | 0.0.1 | | body | { [name: string]: string | number; } | Update body. You can get latitude and longitude data as @latitude and @longitude. | null | 0.0.1 |

GeolocationUpdatesCallbackEvent

| Prop | Type | Description | Since | | --------------- | ------------------- | ----------------------- | ----- | | longitude | number | User location longitude | 0.0.1 | | latitude | number | User location latitude | 0.0.1 |

Type Aliases

GeolocationUpdatesCallback

Each time Geolocation updates, It fires. It's only for forground state.

(data: GeolocationUpdatesCallbackEvent): void

Enums

GeolocationPermissionState

| Members | Value | Description | | ------------- | ---------------------- | --------------------------------- | | granted | "granted" | Geolocation permissions granted | | denied | "denied" | Geolocation permissions denied | | prompt | "prompt" | User has not yet set permissions. |

Full Example


import { Geolocation, GeolocationAlert, GeolocationConnect } from '@aldegad/capacitor-geolocation';

async startLocationUpdates() {
    const permissionOptions:GeolocationPermissionOptions = {
        promptAlert: null,
        deniedAlert: null
    }
    const promptAlert:GeolocationAlertOptions = {
        header: '위치권한 필요',
        message: '이 앱은 원활한 사용을 위해 위치권한을 필요로 합니다.\n위치 권한을 허용해주세요.',
        cancelText: '거부',
        okText: '확인'
    }
    const deniedAlert:GeolocationAlertOptions = {
        header: '위치권한 거부됨',
        message: '이 앱은 원활한 사용을 위해 위치권한을 필요로 합니다.\n[권한 -> 위치]로 이동하여 권한을 허용해주세요.',
        cancelText: '거부',
        okText: '이동'
    }
    permissionOptions.promptAlert = promptAlert;
    permissionOptions.deniedAlert = deniedAlert;
    const { state } = await Geolocation.requestPermission(permissionOptions);
    
    if(state !== 'granted') return;
    
    const updatesOptions:GeololocationUpdatesOptions = {
        background: null,
        notification: null,
        connect: null
    }
    const background:boolean = true;
    const notification:GeolocationNotificationOptions = {
        channelID: 'LOCATION_SERVICE_CHANNEL',
        channelName: '근로자 안전 위치 관리',
        header: '근로자 안전 관리 시스템',
        message: '안전한 근무를 위해 위치관리 시스템을 작동 중 입니다.',
        icon: 'drawable/default_dark'
    }
    const connect:GeolocationConnectOptions = {
        url: 'https://devmonster.co.kr/api/test_log',
        body: {
            user_id: 'ef34f3f3',
            user_position: 'User position is @latitude and @longitude'
        }
    }
    updatesOptions.background = background;
    updatesOptions.notification = notification;
    updatesOptions.connect = connect;
    Geolocation.startLocationUpdates(updatesOptions, ({latitude, longitude}) => {
        console.log();
    });
}
stopLocationUpdates() {
    Geolocation.startLocationUpdates();
}