Android Java - LocationListener taking too long too fetch location even with stable connection

17 views Asked by At

I am trying to fetch users location based on some user action. I am using LocationManager , LocationListener to get the gps co-ordinates . Even when I am using a device with stable connection it takes 15-20 seconds just to fetch the co-ordinates. Is there any way to speed up this process? Is there any way to add timeout to this method.I am attaching the code below .

 LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
        LocationListener locationListener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {...

I have tried to use different methods but they are still giving me the same issue.

1

There are 1 answers

1
Gabe Sechan On

That code you posted isn't enough to get the location, you cut out most of the important parts. But here's a few questions for you to look into:

1)Are you using GPS or network location? Network stability has no impact of speed of getting a location if you're using GPS

2)If using GPS, are you outside with clear line of sight to the sky for satellites, or inside and/or surrounded by tall buildings? Because it can take a while (or literally forever) to get a GPS lock if inside. And there is no way to speed up that process without moving to a better location.