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

@awarns/geolocation

v1.0.0

Published

AwarNS Framework package that allows to acquire the location of the phone on demand

Downloads

38

Readme

@awarns/geolocation

npm (scoped) npm

This module includes tasks to regularly obtain the location of the phone.

This plugin acts as a wrapper on top of the nativescript-context-apis plugin (from the same authors), offering GNSS location acquisition tasks. Acquire phone's location, on demand, even in background.

Install the plugin using the following command line instruction:

ns plugin add @awarns/geolocation

Usage

After installing and setting up this plugin, you'll have access to two different tasks to acquire the location of the phone. The result, will be a Geolocation record, described below.

Tasks

| Task name | Description | |-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | acquirePhoneGeolocation | Allows to acquire the most accurate location available, obtained from the phone, among a few, on demand. The amount of locations to be collected and decide on is configurable | | acquireMultiplePhoneGeolocation | Allows to repeatedly acquire phone locations. Similarly to the single acquisition task, each reported value can be chosen among a few acquired values. Scans will happen for as long as there is execution time remaining (3 minutes max. or shortly before the next time-scheduled task execution, whatever occurs earlier) |

Note: All the tasks require fine location permission and active location services for their execution. Each task will automatically request what is missing during framework's initialization

Acquire a single GNSS location

To register this task for its use, you just need to import it and call its generator function inside your application's task list:

import { Task } from '@awarns/core/tasks';
import { acquirePhoneGeolocationTask } from '@awarns/geolocation';

export const demoTasks: Array<Task> = [
      acquirePhoneGeolocationTask(/* optional */ { bestOf: 3, timeout: 10000 }),
];

Task generator parameters:

| Name | Type | Description | |----------------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | bestOf | number | The number of locations to be collected, to pick the one that is the most accurate. The more locations being requested, the more the task will take to run. The default value is 3 | | timeout | number | Limit the maximum time to be spent collecting locations, in milliseconds. The default value is 10000 (10s). |

Task output events:

Example usage in the application task graph:

on(
  'startEvent',
  run('acquirePhoneGeolocation')
    .every(1, 'minutes')
    .cancelOn('stopEvent')
);

on('geolocationAcquired', run('writeRecords'));

Note: To use the writeRecords, task the persistence package must be installed and configured. See persistence package docs.

Acquire GNSS locations in batch

To register this task for its use, you just need to import it and call its generator function inside your application's task list:

import { Task } from '@awarns/core/tasks';
import { acquireMultiplePhoneGeolocationTask } from '@awarns/geolocation';

export const demoTasks: Array<Task> = [
  acquireMultiplePhoneGeolocationTask(/* optional */ { bestOf: 1, timeout: 15000 }),
];

Task generator parameters:

| Name | Type | Description | |----------------|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | bestOf | number | The number of locations to be collected for each final record being reported, to pick the one that is the most accurate from a subset. The more locations being requested, the lower total amount of locations being reported. This means, in the hypothetical case where there's time to collect 6 locations, with a bestOf value of 1, the 6 locations will be reported, whereas with a bestOf value of 3, in the same situation, only 2 locations will be reported, being these 2 the most accurate among the 2 subsets of 3 locations. The default value is 1 (each location being collected ends being reported) | | timeout | number | Limit the maximum time to be spent collecting each location, in milliseconds. The default value is 15000 (15s). |

Task output events:

Example usage in the application task graph:

on(
  'startEvent',
  run('acquireMultiplePhoneGeolocation', { maxInterval: 10000 /* (Optional) Maximun interval between location acquisitions (this includes the time it takes to obtain all the locations in a reporting subset, if bestOf > 1), unlimited by default */ })
    .every(1, 'minutes')
    .cancelOn('stopEvent')
);

on('geolocationAcquired', run('writeRecords'));

Note: To use the writeRecords task, the persistence package must be installed and configured. See persistence package docs.

Events

| Name | Payload | Description | |-----------------------|---------------------------------------------------------------------|------------------------------------------------------------------| | geolocationAcquired | Geolocation | Array<Geolocation> | Indicates that one or more new GNSS locations have been acquired |

Records

Geolocation

| Property | Type | Description | |----------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | id | string | Record's unique id | | type | string | Always geolocation | | change | Change | Always none. Locations never start or end, they represent spatio-temporal snapshots of where the phone was at a given time. To detect when the phone started and ended being in a place, use the geofencing package | | timestamp | Date | The local time when the location was acquired | | latitude | number | The latitude of where the phone is located at | | longitude | number | The longitude of where the phone is located at | | altitude | number | The altitude of where the phone is located at | | verticalAccuracy | number | The estimated error in the latitude | | horizontalAccuracy | number | The estimated error in the longitude | | speed | number | The estimated speed of the phone by the time the location was acquired | | direction | number | The estimated direction of the phone by the time the location was acquired |

License

Apache License Version 2.0