-1

I use LocationManager to get location,but it can be changed by those APP which can change location.

Y.yang
  • 1
  • 1
  • I think you should put your work to get location that you are talking about. Other wise we don't know how to help you. What IDE are you using? – Whitecat Nov 07 '15 at 06:29

1 Answers1

0

There is an answer already here:

Here is the code he uses to get GPS with location manager.

To make it better, I'll post a snippet. Consider it is in try-catch:

boolean gps_enabled = false;
boolean network_enabled = false;

LocationManager lm = (LocationManager) mCtx
                .getSystemService(Context.LOCATION_SERVICE);

gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

Location net_loc = null, gps_loc = null, finalLoc = null;

if (gps_enabled)
    gps_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (network_enabled)
    net_loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

if (gps_loc != null && net_loc != null) {

    if (gps_loc.getAccuracy() >= net_loc.getAccuracy())
        finalLoc = gps_loc;
    else
        finalLoc = net_loc;

        // I used this just to get an idea (if both avail, its upto you which you want to take as I taken location with more accuracy)

} else {

    if (gps_loc != null) {
        finalLoc = net_loc;
    } else if (net_loc != null) {
        finalLoc = gps_loc;
    }
}
Community
  • 1
  • 1
Whitecat
  • 3,882
  • 7
  • 48
  • 78