mickolasjae
mickolasjae

Reputation: 249

Android's LocationManager class is returning more info than expected

public void getCellLocation1() {

    try {
        LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        Location location = null;

        List<String> providers = manager.getAllProviders();

        for (String provider : providers) {
            location = manager.getLastKnownLocation(provider);
        }
        TextView celllocation = (TextView) findViewById(R.id.txtNewLoc);
        String stlocation = location.toString();
        celllocation.setText(stlocation);
    } catch (Exception a) {
        Log.d("ERRR", "Could not get location", a);
    }
}

This is returning:

Location[network 37.xxxxxx,-122.xxxxxx acc=20 et=+4h41m6s233ms {Bundle[mParcelledData.dataSize=548]}]

Now I understand that I am getting the long, lat, accuracy level and estimated time. It looks like I'm getting this in an array. Is there anyway to break this up? I really would just like the lat and long so that I can use it in a URI to call google maps but any info would be great.

Upvotes: 1

Views: 68

Answers (1)

geekCode
geekCode

Reputation: 336

String sLat = Double.toString(location.getLatitude());
       String  sLong = Double.toString(location.getLongitude());
       String Speed = Double.toString(location.getSpeed());
       String sAlt = Double.toString(location.getAltitude());
       String sTime = Double.toString(location.getTime());

thats the way you get all the info from locationManager

Upvotes: 2

Related Questions