Skip to content

EasyLocationPicker is a library that allows you to pick user location easily on a map, It has geocoder and places autocomplete integrated

License

Notifications You must be signed in to change notification settings

KelvinPac/EasyLocationPicker

Repository files navigation

EasyLocationPicker

Release

An Android library helps you pick user location easily via a callback

  • Fully customizable using the Builder
  • Location is precise up to 7 decimal places (highest precision)
  • Geocoder to give you address and street names
  • User can drag or click on map
  • Integrated Places Autocomplete
  • 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 Kotlin support

Screenshots

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

Usage

  • Declare EasyLocation in your activity
  • Override onActivityResult and call easyLocation.onActivityResult inside it

Example:

public class MainActivity extends AppCompatActivity {

    private EasyLocation easyLocation;
    
    ...
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        easyLocation.onActivityResult(requestCode, resultCode, data);
    }

}
  • Everytime you want to fetch user's current location, simply initialize easyLocation variable:
  • Customize the builder as per your request
   easyLocation = new EasyLocation.Builder(this,"<PLACES_API_KEY>")
                        .showCurrentLocation(true)
                        .useGeoCoder(true)
                        .setResultOnBackPressed(false)
                        .withLocation(location) //you can now provide map location
                        .setCallbacks(new EasyLocationCallbacks() {
                            @Override
                            public void onSuccess(SelectedLocation location) {
                                Toast.makeText(MainActivity.this, location.toString(), Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onFailed(String reason) {
                                Toast.makeText(MainActivity.this, reason, Toast.LENGTH_SHORT).show();
                            }
                        })
                        .build()

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.KelvinPac:EasyLocationPicker:LATEST_VERSION' // this line
}

where LATEST_VERSION is

Kotlin Support

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

private var easyLocation: EasyLocation? = null

...
//open location picker
easyLocation = EasyLocation.Builder(this,"<PLACES_API_KEY>")
                    .useGeoCoder(true)
                    .showCurrentLocation(true)
                    .setResultOnBackPressed(true)
                    .setCallbacks(object : EasyLocationCallbacks{
                        override fun onSuccess(location: SelectedLocation?) {
                            Toast.makeText(this@TestLocationActivity,location.toString(),Toast.LENGTH_SHORT).show()
                        }

                        override fun onFailed(reason: String?) {
                            Toast.makeText(this@TestLocationActivity,reason,Toast.LENGTH_SHORT).show()
                        }
                    })
                    .build()
...

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        easyLocation!!.onActivityResult(requestCode,resultCode,data)
    }
    

Thank you :)

About

EasyLocationPicker is a library that allows you to pick user location easily on a map, It has geocoder and places autocomplete integrated

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages