Giter VIP home page Giter VIP logo

Comments (15)

christocracy avatar christocracy commented on June 1, 2024

If user closes app while stopOnTerminate: false, it's in Apple's hands to
re-awaken the app due to a cell tower change event. Typically 2-3 blocks
of travel the in typical urban environment but depends on the network
environment (i.e. Spacing of cell towers).

stopOnTerminate: false is all you need to do.

Try it in XCode sim.

On Thursday, December 10, 2015, hrpatidar [email protected] wrote:

Hi,

As I am facing, User's location is not updating via our service api while
app is not running in memory and user is moving from one block to another
block. Below code I have implemented so far. Could you please look into
once and let me know where I did wrong.

function startBackgroundGeoLocation()
{
var bgGeo = window.BackgroundGeolocation;

/**

  • This callback will be executed every time a geolocation is recorded in the background.
    */
    var callbackFn = function(location, taskId) {

    /* Location object */
    $scope.updatedLocObj = {
    Latitude:location.coords.latitude,
    Longitude:location.coords.longitude
    }

    /* This is my service API call for update user's location */
    PublicServices.updateCurrentLocation($scope.updatedLocObj).then(function(resp) {
    bgGeo.finish(taskId);
    });
    };

var failureFn = function(error) {
//alert('BackgroundGeoLocation error');
}

// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
// Geolocation config
desiredAccuracy: 0,
stationaryRadius: 50,
distanceFilter: 50,
disableElasticity: false, // <-- [iOS] Default is 'false'. Set true to disable speed-based distanceFilter elasticity
locationUpdateInterval: 5000,
minimumActivityRecognitionConfidence: 80, // 0-100%. Minimum activity-confidence for a state-change
fastestLocationUpdateInterval: 5000,
activityRecognitionInterval: 10000,
stopTimeout: 0,
activityType: 'AutomotiveNavigation',

// Application config
debug: false, // <-- enable this hear sounds for background-geolocation life-cycle.
forceReloadOnLocationChange: false,  // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app when a new location is recorded (WARNING: possibly distruptive to user)
forceReloadOnMotionChange: false,    // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app when device changes stationary-state (stationary->moving or vice-versa) --WARNING: possibly distruptive to user)
forceReloadOnGeofence: false,        // <-- [Android] If the user closes the app **while location-tracking is started** , reboot app when a geofence crossing occurs --WARNING: possibly distruptive to user)
stopOnTerminate: false,              // <-- [Android] Allow the background-service to run headless when user closes the app.
startOnBoot: true,                   // <-- [Android] Auto start background-service in headless mode when device is powered-up.

});

// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
bgGeo.start(); }

Please help me out. Thanks.


Reply to this email directly or view it on GitHub
#23
.

Snet form Gmail Mobile

from cordova-background-geolocation-sampleapp.

hrpatidar avatar hrpatidar commented on June 1, 2024

Ok. Means code settings is fine. And the server api call is well placed? And these code should be same for Android devices. Right?

from cordova-background-geolocation-sampleapp.

christocracy avatar christocracy commented on June 1, 2024

Android performs much better in this respect. It is not affected by user
closing app (it runs as a background service, immune from user).

On Thursday, December 10, 2015, hrpatidar [email protected] wrote:

Ok. Means code settings is fine. And the server api call is well placed?
And these code should be same for Android devices. Right?


Reply to this email directly or view it on GitHub
#23 (comment)
.

Snet form Gmail Mobile

from cordova-background-geolocation-sampleapp.

hrpatidar avatar hrpatidar commented on June 1, 2024

Yes. I have seen like when I am moving 2-3 blocks, Android device is automatically sounding. So that time callback will be executed and our server api as well?

from cordova-background-geolocation-sampleapp.

christocracy avatar christocracy commented on June 1, 2024

You've purchased the Android version? You should be using the private repo
for questions.

On Thursday, December 10, 2015, hrpatidar [email protected] wrote:

Yes. I have seen like when I am moving 2-3 blocks, Android device is
automatically sounding. So that time callback will be executed and our
server api as well?


Reply to this email directly or view it on GitHub
#23 (comment)
.

Snet form Gmail Mobile

from cordova-background-geolocation-sampleapp.

hrpatidar avatar hrpatidar commented on June 1, 2024

Yes. I have purchased the Android version.

from cordova-background-geolocation-sampleapp.

christocracy avatar christocracy commented on June 1, 2024

When you hear the tracking sound, the plugin has executed an HTTP request
(with autoSync: true and and #url to your server configured.)

On Thursday, December 10, 2015, hrpatidar [email protected] wrote:

Yes. I have seen like when I am moving 2-3 blocks, Android device is
automatically sounding. So that time callback will be executed and our
server api as well?


Reply to this email directly or view it on GitHub
#23 (comment)
.

Snet form Gmail Mobile

from cordova-background-geolocation-sampleapp.

hrpatidar avatar hrpatidar commented on June 1, 2024

Ok. But in above my code, I have mentioned our server api call in 'callbackFn' function. It is fine?
I am a bit confused here. I need to set below HTTP config as well :

   // HTTP  config
    url: 'http://posttestserver.com/post.php?dir=cordova-background-geolocation',
    method: 'POST',
    batchSync: true,     
    autoSync: true,       
    maxDaysToPersist: 1

And also 'url' parameter value should be our server api url instead of above?

Sorry for more questions. But please clear me.

Thanks

from cordova-background-geolocation-sampleapp.

christocracy avatar christocracy commented on June 1, 2024

To send the location to your server, you have 2 options:

  1. (Not recommended) Use JavaScript callback to receive the location and
    Manually post via Ajax.
  2. (Recommended) allow the plugin to automatically post locations to your
    server using native http request. Simply configure an #url to your server
    as well as optional #params, #headers.

On Thursday, December 10, 2015, hrpatidar [email protected] wrote:

Ok. But in above my code, I have mentioned our server api call in
'callbackFn' function. It is fine?
I am a bit confused here. I need to set below HTTP config as well :

// HTTP config
url: 'http://posttestserver.com/post.php?dir=cordova-background-geolocation',
method: 'POST',
batchSync: true,
autoSync: true,
maxDaysToPersist: 1

And also 'url' parameter value should be our server api url instead of
above?

Sorry for more questions. But please clear me.

Thanks


Reply to this email directly or view it on GitHub
#23 (comment)
.

Snet form Gmail Mobile

from cordova-background-geolocation-sampleapp.

hrpatidar avatar hrpatidar commented on June 1, 2024

Great. I have implemented option 2. Defined the url, header and param as well.

Question is, My server HTTP request type is PUT. And request accepted JSON is {Latitude: 'any location lat', Longitude: 'any location long'}. I have added this JSON as a param. So when application is running, it is updating the locations to server. Fine. But app is not running in memory then how plugin will call HTTP request with this JSON?(With updated Latitude and Longitude). Means how plugin will communicate with my param object? see below HTTP config:

           // HTTP config
            url: 'test.testadmin.com/location',
            method: 'PUT',
            batchSync: false,     
            autoSync: true,
            maxDaysToPersist: 1, 
            headers: {
            "hk-AuthToken":'egt4573647fdcdf6h5j6h5'
            },
            params: {Latitude: '23.6565', Longitude: 45.56565'}

And background call would be depend of cell towers change event. Means a device without sim will not able update location to server. Correct?

Thanks

from cordova-background-geolocation-sampleapp.

christocracy avatar christocracy commented on June 1, 2024

Why are you adding Latitude, Longitude to params?? That's not what params are for. Do not do this. The plugin automatically appends the location-data to the HTTP request using the following Location Schema:

You MUST reconfigure your server to consume this schema:

{
    "location": {
        "coords": {
            "latitude":   [Float],
            "longitude":  [Float]
            "accuracy":   [Float]
            "speed":      [Float],
            "heading":    [Float],
            "altitude":   [Float]
        },
        "extras": {   // <-- optional extras.  @see #getCurrentPosition for details
            "foo": "bar"
        },
        "activity": {
            "type": [still|on_foot|walking|running|in_vehicle|on_bicycle],
            "confidence": [0-100%]
        },
        "geofence": {  // <-- Present only if a geofence was triggered at this location
            "identifier": [String],
            "action": [String ENTER|EXIT]            
        },
        "battery": {
            "level": [Float],
            "is_charging": [Boolean]
        },
        "timestamp": [ISO-8601 UTC], // eg:  "2015-05-05T04:31:54.123Z"
        "uuid":      [String],       // <-- Universally unique identifier
        "is_moving": [Boolean],      // <-- The motion-state when location was recorded.
        "is_heartbeat: [Boolean]     // <-- If this location was recorded during heartbeat mode.
    }
}

This plugin runs as a Background Service, unaffected by teh user closing the app (with stopOnTerminate: false. It will continue to send locations to your server.

from cordova-background-geolocation-sampleapp.

christocracy avatar christocracy commented on June 1, 2024

As for HTTP method, the plugin has a config param method which you can set to PUT. You will do yourself a favour to quickly spend 2 minutes and simply read every available configuration option.

EDIT: Sorry, I see you did in fact set method: 'PUT'.

from cordova-background-geolocation-sampleapp.

hrpatidar avatar hrpatidar commented on June 1, 2024

Thanks Chris. Means no need to set any param from my side. Only just need to reconfigure data at my server side.

from cordova-background-geolocation-sampleapp.

meggii avatar meggii commented on June 1, 2024

Background service send data when app is running and when app terminate background service stop sendindg data... how it works all time

from cordova-background-geolocation-sampleapp.

christocracy avatar christocracy commented on June 1, 2024

iOS or Android?

from cordova-background-geolocation-sampleapp.

Related Issues (20)

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.