Giter Club home page Giter Club logo

fusedlocation's Introduction

Titanium Android FusedLocation

Summary

FusedLocation is an open-source project to support the Android's new LocationRequest in Appcelerator's Titanium Mobile.

Requirements

  • Titanium Mobile SDK 6.1.0.GA or later
  • Android 2.3 or later

Download + Setup

Download

Setup

Unpack the module and place it inside the modules/android/ folder of your project. Edit the modules section of your tiapp.xml file to include this module:

<modules>
    <module platform="android">ca.underlabs.fusedlocation</module>
</modules>

Features

Start Location (location updates event)

var FusedLocation = require('ca.underlabs.fusedlocation');

GoogleApiClient.startGeoLocation({
    success: function(e) {
        // returns similar to iOS location event: 
        // {"type":"location","success":true,"provider":"fused",
        //      "coords":{"bearing":0,"latitude":40.4688283,"timestamp":1486002223000,"speed":0,"accuracy":1,"longitude":-72.74637}}
        Ti.API.info(JSON.stringify(e)); 
        // handleLocation(e); // create a function that handles the event for both platforms!
    },
    error: function(e) {
        Ti.API.info('Android GeoLocation Fusion Error :(');
        Ti.API.info(JSON.stringify(e));
    }
});

Stop Location (save on battery consumption when not needed)

GoogleApiClient.stopGeoLocation();

Defaults

By Default in the code (hardcoded - pull requests welcomed):

  • PRIORITY is set to 100 (meaning GPS - Most Accurate)
  • DISTANCE_FILTER is set to 5 meters (location event updates when accelerometers senses that 5 meters have been traversed)

If Distance Filter is triggered (example driving very fast), below are handled by:

  • FASTEST_UPDATE_FREQ is set to 1 second (every 1 sec at fastest)
  • INTERVAL is set to 5 second (at latest)

Usage with ti.map

Make sure to delete in /1.2.1/lib/ these 2 jars:

  • classes-base.jar and
  • classes-basement.jar

Since they’re already in ti.map, and just leave classes.jar (which holds com.google.android.gms.location)

Build

If you want to build the module from the source, you need to check some things beforehand:

  • You'll need all three .jar files in your build path
  • With Ti >= 6.1.0, use within android folder appc run --build-only

TODO: These are Hardcoded - PullRequests are Welcomed, and I will try to update it so that these can be passed from Ti App part of startGeoLocation.

TODO

[ ] Allow params to be passed to startGeoLocation for: priority, distanceFilter, fastestInterval and interval

Contributing

Code contributions are greatly appreciated, please submit a new pull request!

fusedlocation's People

Contributors

yozef avatar

Watchers

James Cloos avatar

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.