This library contains all utils related to google location. like, getting lat or long, Address and Location Setting dialog, Draw Route, etc.

What's New in Ver 2.0

  • Route Draw
    a. simple.
    b. animation.

  • Make sure performance is good by using kotlin coroutine.

  • Draw route between origin and destination through waypoints.

  • The callback of the complete route draws with time and distance between waypoints and destinations.






  • Android 16


Step 1:- Add it in your root build.gradle at the end of repositories:

all projects {
        repositories {
            maven { url 'https://jitpack.io' }

Step 1:- Add the dependency:

        dependencies {
            implementation 'com.github.prabhat1707:EasyWayLocation:2.0'


If the device is running Android 6.0 or higher, and your app's target SDK is 29 or higher then first check the permission of location then call it.

Add the required permissions

For fine location (GPS location), add the following permission in your AndroidManifest.xml:

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

For coarse location (network location), add the following permission in your AndroidManifest.xml:

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

Retrieve the location from the device

public class MainActivity extends AppCompatActivity implements Listener {
    EasyWayLocation easyWayLocation;
    private TextView location, latLong, diff;
    private Double lati, longi;

    protected void onCreate(Bundle savedInstanceState) {
        easyWayLocation = new EasyWayLocation(this, false,this);

    public void locationOn() {
        Toast.makeText(this, "Location ON", Toast.LENGTH_SHORT).show();    

    public void currentLocation(Location location) {
        StringBuilder data = new StringBuilder();
        data.append(" , ");
        getLocationDetail.getAddress(location.getLatitude(), location.getLongitude(), "xyz");
    public void locationCancelled() {
         Toast.makeText(this, "Location Cancelled", Toast.LENGTH_SHORT).show();

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {

    protected void onResume() {

    protected void onPause() {


Location Notifier

    public void locationOn() {
        Toast.makeText(this, "Location ON", Toast.LENGTH_SHORT).show();

    public void  currentLocation(Location location){
       // give lat and long at every interval 

    public void locationCancelled() {
        // location not on

Constructor options

Points to Remember

  • if you want only last location then pass it true and if false then it gives you location update as per default location request.
  • if you don't pass then it takes default location request or you can pass your's one also(see constructor 2nd).
Context context = this;
boolean requireFineGranularity = false;
new EasyWayLocation(this, requireLastLocation = false,listner = this);


request = new LocationRequest();

new EasyWayLocation(this,locationRequest = request ,  requireLastLocation = false,listner = this);

Calculate distance between two points

double startLatitude = 59.95;
double startLongitude = 30.3;
double endLatitude = 44.84;
double endLongitude = -0.58;
location.calculateDistance(startLatitude, startLongitude, endLatitude, endLongitude);

// or

Point startPoint = new EasyWayLocation.Point(59.95, 30.3);
Point endPoint = new EasyWayLocation.Point(44.84, -0.58);
location.calculateDistance(startPoint, endPoint);

Update Get Address Details of location.

  • if you want an address from the current location then you need to pass key and context.
  • why I want key here if android already provides Geocoder because in some cases or some devices geocoder not work well and throws Exception, so in that case, I use google geocode API for fetch address.
  • For this, you need to implement Callback, LocationData.AddressCallBack
GetLocationDetail getLocationDetail = new GetLocationDetail(callback = this, context = this);

getLocationDetail.getAddress(location.getLatitude(), location.getLongitude(), key = "xyz");

Google Map Route

If you want to add map route feature in your apps you can use this along with this lib by adding DirectionUtil Class to make you work more easier. This is lib will help you to draw route maps between two-point LatLng along it's with waypoints.

In Your GoogleMap Ready

Make sure you enable google map and google map direction in the google developer console.

wayPoints.add(LatLng(37.423669, -122.090168))
        wayPoints.add(LatLng(37.420930, -122.085362))
                val directionUtil = DirectionUtil.Builder()
                        .setOrigin(LatLng(37.421481, -122.092156))
                        .setDestination(LatLng(37.421519, -122.086809))


There are two cases in it:

  • With Animation like Uber
  • without Animation.
  1. With Animation

    • setPathAnimation = true


  1. Without Animation

    • setPathAnimation = false
    • change its color by, setPolyLinePrimaryColor() property



When route draw path has done then it comes in a callback

override fun pathFindFinish(polyLineDetails: HashMap<String, PolyLineDataBean>) {
       for (i in polyLineDetails.keys){

here, polyLineDetails contain each polyline or route detail as time, distance and road summary.

You can also change the route animation different properties like delay, primary color, a secondary color, etc, just explore it.

Bugs, Feature requests

Found a bug? Something that's missing? Feedback is an important part of improving the project, so, please
open an issue