Giter Club home page Giter Club logo

airlocation's Introduction

alt text

AirLocation

PayPal donate button

An Android library which simply gets you user's most precise current location via a callback!

  • Location is precise up to 7 decimal places (highest precision)
  • No need to add any permissions in manifest manually
  • No need to add google play services location lib in gradle manually
  • Uses Google location services API internally - so you're in safe hands
  • Simple plug and play design
  • Full Java support
(method counts ~50, size ~50KB)

Screenshots

alt text alt text
alt text alt text
alt text alt text

Usage

  • Declare airLocation in your activity
  • Override onActivityResult and call airLocation.onActivityResult inside it
  • Override onRequestPermissionsResult and call airLocation.onRequestPermissionsResult inside it

Example:

class MainActivity : AppCompatActivity() {

    private var airLocation: AirLocation? = null // ADD THIS LINE ON TOP
    
    ...
    
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        airLocation?.onActivityResult(requestCode, resultCode, data) // ADD THIS LINE INSIDE onActivityResult
        super.onActivityResult(requestCode, resultCode, data)
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        airLocation?.onRequestPermissionsResult(requestCode, permissions, grantResults) // ADD THIS LINE INSIDE onRequestPermissionResult
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }
    
}
  • Everytime you want to fetch user's current location, simply initialize airLocation variable:
airLocation = AirLocation(this, true, true, object: AirLocation.Callbacks {
                override fun onSuccess(location: Location) {
                    // location fetched successfully, proceed with it
                }

                override fun onFailed(locationFailedEnum: AirLocation.LocationFailedEnum) {
                    // couldn't fetch location due to reason available in locationFailedEnum
                    // you may optionally do something to inform the user, even though the reason may be obvious
                }

            })

Setup

Add this line in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' } // this line
  }
}

Add this line in your app build.gradle:

dependencies {
  implementation 'com.github.mumayank:AirLocation:LATEST_VERSION' // this line
}

where LATEST_VERSION is

Java Support

This library fully supports Java out of the box (because Kotlin is 100% interoperable) Hence the setup remains the same, and usage becomes:

public class MainJavaActivity extends AppCompatActivity {

    // In your activity, define this variable at top-level
    private AirLocation airLocation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_java);

        // Fetch location simply like this whenever you need
        airLocation = new AirLocation(this, true, true, new AirLocation.Callbacks() {
            @Override
            public void onSuccess(@NotNull Location location) {
                // do something
            }

            @Override
            public void onFailed(@NotNull AirLocation.LocationFailedEnum locationFailedEnum) {
                // do something
            }
        });
    }

    // override and call airLocation object's method by the same name
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        airLocation.onActivityResult(requestCode, resultCode, data);
    }

    // override and call airLocation object's method by the same name
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        airLocation.onRequestPermissionsResult(requestCode, permissions, grantResults);

    }
}

How it works?

I was working on an app where I was required to fetch my app user's current location with highest precision, and accuracy. I looked it up on Android app development documentation where it was mentioned to use Google location services library for the same. My experience wasn't pleasant. It is difficult, complex, and painful to implement. I mean, everytime I want to fetch user's location, I have to do all those things! No way!

I started looking for alternatives. I mean, why do so much of work for such a redundant task? But I couldn't find a suitable library for my use. Hence, I decided to go back to Google location services library. After days of struggle, I was finally able to make it work for all scenarios. Then it hit me - so many developers out there might be going through the same pain as I, specially junior android app developers. Shouldn't there be something as simple as a callback to get user's current location? Hence I decided to publish my work in the form of this library.

  • You don't have to manually add permissions in manifest as the library's manifest contains those and whenever your app builds, manifests are merged resulting in permissions getting added to your app's manifest automatically.
  • You don't have to add Google location services library in your app's gradle.build file as the library's gradle.build file contains it
  • You don't have to ask location permission or location optimization permission at runtime because the library handles that for you
  • You will simply get the location via plug and play of this library.

Future

I am working on getting live location of user. Will update the library soon. Stay tuned!

Thank you :)

airlocation's People

Contributors

mumayank avatar

Watchers

 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.