GithubHelp home page GithubHelp logo

mirrorcell-geolocation-plus's Introduction

Provides an abstraction (Location) from navigator.geolocation that is used to retrieve coordinates / speed / etc from browsers and mobile devices.

NOTE : This plugin is for foreground Geolocation, if you need background geolocation, use: mirrorcell:background-geolocation-plus

New For 1.1.3!

  • Get The GPS Status Of Android / iOS and display a native prompt if GPS is Disabled That Takes the User to relevant settings pages -- Please look at the documentation below for an example.

Advantages of this package over meteor's core package:

* NEW - Get the GPS Status / Show Dialog  Natively.
* Provides reactive and non reactive options to retrieve position
* Manually stop and start watching positions (original watches continuously, horrible for battery)
* Manually get a one time position
* Options to automatically filter for distance between points, time between locations, and gps accuracy

To retrieve the status of the GPS:

Location.getGPSState

//Success Will fire upon completion of the GPS check
//State will be different for Android and iOS

//Android States:
//Enabled
//Disabled

//iOS States: (See IOS KClAuthorizationStatus Documentation for more information)
//NotDetermined -- Never asked user for auhtorization
//Denied -- Asked User for authorization but they denied
//Restricted -- Same As Not Determined

function success(state) {
   if(state === 'Enabled') {
      console.log("GPS Is Enabled");
   }
}

//This will fire if either your not running in a cordova application
//Or the plugin was not found for some reason
function failure() {
   console.log("Failed to get the GPS State");
}

//Options: The only option right now is to show 
//a dialog if gps is disabled. The dialog has a 
//button on it that directs the user to the settings
//page assocaited with enabling their gps for your app.
// Dialog : true means the pop up will appear
var options = {
   dialog: true
}

Location.getGPSState(success, failure, options);

Pictures Of said gps dialog:

alt text alt text

How to use:

To get a new coordinate(s) - these functions retrieve coordinates from the gps and store the results, reactively, and in local storage automatically, they also return callbacks so you can add your own custom logic / processing.

Location.locate - Gets a single GPS coordinate upon call

Location.locate(function(pos){
   console.log("Got a position!", pos);
}, function(err){
   console.log("Oops! There was an error", err);
});

Location.startWatching -- Continually pings the GPS for new positions, stores in local storage, and the reactive var

Location.startWatching(function(pos){
   console.log("Got a position!", pos);
}, function(err){
   console.log("Oops! There was an error", err);
});

Location.stopWatching -- Stops the currently running watcher

Location.stopWatching();

Location.setMockLocation -- Sets a Mock (test) position. Useful for testing in the browser. you can set any combination of the fields, none are required. Each field's default is 0. Will update the local storage and reactive position object.

Location.setMockLocation({
   latitude : ...
   longitude : ...
   accuracy : ...
   speed : ...
   altitude : ...
   altitudeAccuracy : ...
   updatedAt : ...
});

To retrieve coordinates --

Location.getReactivePosition()

* Retrieves a reactive variable that updates from locate and startWatching

Location.getLastPosition()

* Retrieves the stored non-reactive but Persistent (Local Storage)

Both return object of :

var pos = {
        latitude : ...
        longitude : ...
        accuracy : ...
        speed : ...
        altitude : ...
        altitudeAccuracy : ...
        updatedAt : ...
    }

Filtering:

  • Distance: Filters any GPS coordinate retreived from the GPS by distance. For example, if you change Locate.distanceFilter.range to 5, any GPS coordinates not 5 meters from the last coordiante retrieved will not be returned or saved.
  • Accuracy: Filters any GPS coordinate retrieved from the GPS by accuracy. For example, if you change Locate.accuracyFilter.rating to 10, any GPS coordinates not 10 accuracy or more will not be returned or saved.
  • Time: Filters any GPS coordinate retrieved from the GPS by time (in minutes). For example, if you change Locate.timeFilter.lapse to 1, any GPS coordinates not 1 minute or longer from the last coordinate retrieved will not be returned or saved.

You can use any of these filters in conjunction. To enable any or all of these:

  • Location.enableAccuracyFilter(rating)

  • Location.enableDistanceFilter(distance)

  • Location.enableTimeFilter(span)

You can disable any of these by calling their specific disable function or Location.disableAllFilters()

Setting GPS options

  • setWatchOptions(optionsObject) -- Sets the options for Location.watchPosition ( see docs for navigator.geolocation.watchPosition for options)
  • setGetPositionOptions(optionsObject) -- Sets the options for Location.locate ( see docs for navigator.geolocation.getCurrentPosition for options)

Debug -

To Turn on debugging console message: Set Location.debug = true

mirrorcell-geolocation-plus's People

Contributors

pmwisdom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mirrorcell-geolocation-plus's Issues

How to allow background geolocation on the phone ?

Hi,
Thanks a lot for this great plugin !
It works perfectly on my app, except that the phone doesn't prompt the user to explain that myApp would like to use the user's geolocation all the time.
Therefore, when the application is in background, I get a blue alert on top of screen saying thet myApp is "using geolocation data".
I can get rid of this by going in my phone's setup, and allow background geolocation for myApp, but it's definitely not possible to request this from all my users.

So is there a way to trigger the iOS command tu allow background geolocation from my meteor app ?

Thanks a lot for your help on this (maybe stupid?) question !

Speed always returns Null

The 'speed' property of the 'position' object always returns 'Null'. This, in the browser, on iOS and on Android.

Am I missing something obvious? Or, is there no way to obtain the device speed?

(Of course, I can calculate the speed of the device based on changing lat/lng, but that turns out to be very inaccurate, as even a device at rest sees its lat/lng continuously changed.)

Function with direct link to gps settings page

we would like a function which directs the user to the gps settings page. This will help us to further customize the user experience. (its the link in the dialog button we would like to use)

setMockLocation

Readme says
setMockPosition,
but it should be
setMockLocation

Update Cordova dependencies

WARNING: Attempting to install plugin [email protected], but it should have a minimum version of 2.4.3 to ensure
compatibility with the current platform versions. Installing the minimum version for convenience, but you should adjust
your dependencies.

Any chance we could get the dependency upped to the minimum version specified by Cordova?

Support for newer version of cordova

We tried to use this package with Meteor 1.3 (which has cordova v. 6) and we keep getting compile errors. Will you be adding support for Meteor 1.3?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.