Code Monkey home page Code Monkey logo

bearing's Introduction

Bearing

The Bearing library is for simplifying location based requests into a simple, fluent API. All requests are asynchronous and callback to configured listeners.

This is a project for the community. All pull requests and bug reports are welcome and encouraged!

Using bearing in your project

The library is on maven central, and can be included in your gradle project by adding:

compile "net.atomcode:bearing:<latest_version>"

Or, if using maven by adding:

<dependency>
    <groupId>net.atomcode</groupId>
    <artifactId>bearing</artifactId>
    <version>(latest version)</version>
</dependency>

Android permissions

Currently, in order to use the library your app will need the following permissions in the android manifest:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

The location permission is, naturally for getting the location of the user. Only FINE is required here as FINE implies COARSE. The internet permission is required for geocoding and some fallback requests.

Current location

Get the current location of the user

Bearing.with(context).locate().listen({...}).start();

The current location module also allows the definition of a required accuracy of the request.

Bearing.with(context).locate().accuracy(Accuracy.HIGH).listen({...}).start();

The default accuracy is MEDIUM which gives the location to the nearest 50m

Tracking (EXPERIMENTAL)

There is currently experimental support for user tracking

Bearing.with(context).track().listen({...}).start();

Tracking currently uses a LOT of battery by default, and needs configuring to use low power sources, and a large step time. i.e.

Bearing.with(context).track()
    .displacement(1000)
    .rate(60*60*1000)
    .accuracy(Accuracy.LOW)
    .listen({...})
    .start();

Please use this feature with caution it is still a work in progress.

Geocoding

To get a list of possible addresses with lat,lng coordinates for a given query

Bearing.with(context).geocode("New York, NY").listen({...}).start();

Other configurable options include the number of results to return (Default: 10)

Bearing.with(context).geocode("New York, NY").results(5).listen({...}).start();

Reverse Geocoding

Bearing also supports reverse geocoding. The action of turning a lat,lng pair into an address

Location location;
Bearing.with(context).geocode(location).listen({...}).start();

Bearing supports Reverse Geocoding for the following objects:

android.location.Location;
android.location.Address;
com.google.android.gms.maps.model.LatLng;

bearing's People

Contributors

scruffyfox avatar tom-bell avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bearing's Issues

Multiple results

Let Bearing#getAddressListForQuery return a full list of results rather than just forcing one and add an additional method to return a single result

Feature request: timeout

Would be good to have the ability to set a timeout for the location to error after x amount of time

No class def error

Apparently LocationClient has now been removed and is causing a crash when trying to fetch a users location

 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/location/LocationClient;
            at net.atomcode.bearing.location.provider.GMSLocationProvider.create(GMSLocationProvider.java:48)
            at net.atomcode.bearing.location.LocationTask.<init>(LocationTask.java:50)
            at net.atomcode.bearing.location.CurrentLocationTask.<init>(CurrentLocationTask.java:13)
            at net.atomcode.bearing.Bearing.locate(Bearing.java:151)
            at MainActivity.onCreate(MainActivity.java:80)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5146)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.location.LocationClient" on path: DexPathList[[zip file "/data/app/help.com.cube.emergencyhelp-1.apk"],nativeLibraryDirectories=[/data/app-lib/help.com.cube.emergencyhelp-1, /vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at net.atomcode.bearing.location.provider.GMSLocationProvider.create(GMSLocationProvider.java:48)
            at net.atomcode.bearing.location.LocationTask.<init>(LocationTask.java:50)
            at net.atomcode.bearing.location.CurrentLocationTask.<init>(CurrentLocationTask.java:13)
            at net.atomcode.bearing.Bearing.locate(Bearing.java:151)
            at MainActivity.onCreate(MainActivity.java:80)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5146)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
    Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.location.LocationClient
            at java.lang.Class.classForName(Native Method)
            at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
            at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 18 more
     Caused by: java.lang.NoClassDefFoundError: Class "Lcom/google/android/gms/location/LocationClient;" not found
            ... 22 more

Cant cancel location request

In LegacyLocationProvider you need to add in create(Context context)

if(runningRequests == null){
            runningRequests = new HashMap<>();
        }

Random crash

java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
at com.google.android.gms.internal.ff.bT(Unknown Source)
at com.google.android.gms.internal.hc.a(Unknown Source)
at com.google.android.gms.internal.hc$c.bT(Unknown Source)
at com.google.android.gms.internal.hb.requestLocationUpdates(Unknown Source)
at com.google.android.gms.internal.hc.requestLocationUpdates(Unknown Source)
at com.google.android.gms.internal.hc.requestLocationUpdates(Unknown Source)
at com.google.android.gms.location.LocationClient.requestLocationUpdates(Unknown Source)
at net.atomcode.bearing.location.provider.GMSLocationProvider.internalRequestSingleUpdate(GMSLocationProvider.java:258)
at net.atomcode.bearing.location.provider.GMSLocationProvider.access$000(GMSLocationProvider.java:25)
at net.atomcode.bearing.location.provider.GMSLocationProvider$1.run(GMSLocationProvider.java:89)
at net.atomcode.bearing.location.provider.GMSLocationProvider.onConnected(GMSLocationProvider.java:298)
at com.google.android.gms.internal.ff$c.onConnected(Unknown Source)
at com.google.android.gms.internal.fg.b(Unknown Source)
at com.google.android.gms.internal.fg.bV(Unknown Source)
at com.google.android.gms.internal.ff$h.b(Unknown Source)
at com.google.android.gms.internal.ff$h.a(Unknown Source)
at com.google.android.gms.internal.ff$b.eN(Unknown Source)
at com.google.android.gms.internal.ff$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

Not sure the cause but it has something to do with this http://stackoverflow.com/questions/21107237/not-connected-call-connect-or-wait-for-onconnected-to-be-called

Cancelling a LocationTask does not cancel the underlying google task

Calling cancel on a LocationTask object does not cancel the underlying Google location service. This appears to be because taskId is never set by subclasses and so is always null.

I believe for PeriodicLocationTask it should be set to the result of locationProvider.requestRecurringLocationUpdates?

Cheers

No catch for null listeners (v2.+)

Currently crashes if you do not provide a listener

https://github.com/tom-bell/Bearing/blob/v2.2.3/src/main/java/net/atomcode/bearing/location/CurrentLocationTask.java#L32

    java.lang.NullPointerException: Attempt to invoke virtual method 'void net.atomcode.bearing.location.LocationListener.onUpdate(android.location.Location)' on a null object reference
            at net.atomcode.bearing.location.CurrentLocationTask$1.onUpdate(CurrentLocationTask.java:32)
            at net.atomcode.bearing.location.provider.GMSLocationProvider$5.onLocationChanged(GMSLocationProvider.java:246)
            at com.google.android.gms.internal.hb$a.handleMessage(Unknown Source)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)

Missing Address population for fallback geocoding.

When Bearing makes a geocoding request and a suitable service is not available on the device, it falls back to the web service. However in contrast to the geocoding service it does not populate the Address object with the returned JSON.

Crash with registering for location callbacks

java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
           at com.google.android.gms.internal.eh.bm(Unknown Source)
           at com.google.android.gms.internal.hi.a(Unknown Source)
           at com.google.android.gms.internal.hi$c.bm(Unknown Source)
           at com.google.android.gms.internal.hh.requestLocationUpdates(Unknown Source)
           at com.google.android.gms.internal.hi.requestLocationUpdates(Unknown Source)
           at com.google.android.gms.internal.hi.requestLocationUpdates(Unknown Source)
           at com.google.android.gms.location.LocationClient.requestLocationUpdates(Unknown Source)
           at net.atomcode.bearing.location.provider.GMSLocationProvider.internalRequestRecurringUpdates(GMSLocationProvider.java:189)
           at net.atomcode.bearing.location.provider.GMSLocationProvider.access$100(GMSLocationProvider.java:25)
           at net.atomcode.bearing.location.provider.GMSLocationProvider$2.run(GMSLocationProvider.java:111)
           at net.atomcode.bearing.location.provider.GMSLocationProvider.onConnected(GMSLocationProvider.java:284)
           at com.google.android.gms.internal.eh$c.onConnected(Unknown Source)
           at com.google.android.gms.internal.ei.b(Unknown Source)
           at com.google.android.gms.internal.ei.bo(Unknown Source)
           at com.google.android.gms.internal.eh$h.b(Unknown Source)
           at com.google.android.gms.internal.eh$h.a(Unknown Source)
           at com.google.android.gms.internal.eh$b.ec(Unknown Source)
           at com.google.android.gms.internal.eh$a.handleMessage(Unknown Source)
           at android.os.Handler.dispatchMessage(Handler.java:99)
           at android.os.Looper.loop(Looper.java:137)
           at android.app.ActivityThread.main(ActivityThread.java:5103)
           at java.lang.reflect.Method.invokeNative(Native Method)
           at java.lang.reflect.Method.invoke(Method.java:525)
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
           at dalvik.system.NativeStart.main(Native Method)

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.