Android location manager returns the same GPS coordinates every time

I am creating an application to send phone locations to my server. The problem is that the phone gives me the same GPS coordinates every time I launch the application. When I restart it, the coordinates may change, but after sending the first coordinate, it will send the same time until the application is restarted.

code:

// Contructor etc public class LocationASYNC extends AsyncTask<Activity, String, Void> { private MainActivity m; private LocationManager locationManager; private Criteria c; public LocationASYNC(MainActivity m) { this.m = m; locationManager = (LocationManager) m .getSystemService(Context.LOCATION_SERVICE); c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_FINE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, m); } // Code for finding best location provider and returning location private Location findBestLocation() { Location location = locationManager .getLastKnownLocation(locationManager.getBestProvider(c, true)); Log.v("location", "provider: " + locationManager.getBestProvider(c, true)); // Check if location is null if (location != null) { Log.v("location", "provider not null"); // Test if location is more than 100 seconds old if (location.getTime() < (System.currentTimeMillis() - 100000)) { Log.v("location", "provider is old(GPS)"); // Use network if location is more than 100 seconds (99% chance // location will be gps) location = locationManager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // Check if network location is more then 100 seconds Log.v("location", "provider: " + location.getProvider()); if (location.getTime() < (System.currentTimeMillis() - 100000)) { // Return null if all location data is old Log.v("location", "provider is old (INT)"); return null; } } // Return location if one is less than 100 seconds old return location; } // return null if no location is found return null; } This is the output i get from logcat: 02-05 15:31:59.670: V/location(29659): provider: network 02-05 15:31:59.675: V/location(29659): lat: 60.3935485 lon: 5.3114676 time: 1360074627953 acc: 28.757 02-05 15:32:02.685: V/location(29659): provider: gps 02-05 15:32:02.685: V/location(29659): provider not null 02-05 15:32:02.685: V/location(29659): provider is old(GPS) 02-05 15:32:02.690: V/location(29659): provider: network 02-05 15:32:02.690: V/location(29659): lat: 60.3935485 lon: 5.3114676 time: 1360074627953 acc: 28.757 02-05 15:32:05.700: V/location(29659): provider: gps 02-05 15:32:05.700: V/location(29659): provider not null 02-05 15:32:05.705: V/location(29659): provider is old(GPS) 02-05 15:32:05.710: V/location(29659): provider: network 02-05 15:32:05.710: V/location(29659): lat: 60.3935485 lon: 5.3114676 time: 1360074627953 acc: 28.757 02-05 15:32:08.720: V/location(29659): provider: gps 02-05 15:32:08.720: V/location(29659): provider not null 02-05 15:32:08.720: V/location(29659): provider is old(GPS) 02-05 15:32:08.725: V/location(29659): provider: network 02-05 15:32:08.725: V/location(29659): provider is old (INT) 

Latitude and longitude are the same for each journal entry, as well as time (millisecond since 1980 or so). Same.

It seems that my application gets a place once and no longer tries to get a position.

+4
source share
1 answer

Try checking if GPS is turned on on your device or if your device supports GPS.

0
source

All Articles