Tag Archives: java

Android vs Google Glass LocationManager

I’ve played around with location a lot in the past year at Sabre Labs, and also in my previous job at Geoforce.  I find it very interesting and fun to work with.  Recently in The Lab we took on a Google Glass project.  The Glass is an interesting animal.  It runs Android, but it’s ever so slightly different.   One area that tripped me up was location.

So, here is a comparison of LocationManager in Android vs LocationManager in Google Glass.


// Android-flavored location
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 35000, 10, this);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 35000, 10, this);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);

Google Glass:

// Google Glass-flavored location
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
List<String> providers = locationManager.getProviders(criteria, true);
for (String provider : providers) {
    Log.d(TAG, provider);
    location = locationManager.getLastKnownLocation(provider);
    if (location != null) {
        // one location is probably sufficient
    } else {
        // probably don't need regular updates, but if we miss a last known location we might
        locationManager.requestLocationUpdates(provider, 35000, 10, this);

You’ll note that there is an extra context. before the getSystemService call in the Glass example. That’s because I put the LocationManager in a separate singleton class, so I get the app’s context first.

I wanted to have a lot of utility classes off the main UI thread, and I only needed location to support a subset of API calls that I fire off to our service. HTTP requests have to be done asynchronously, so I had a good clean line of delineation between the view layer and object models.

Leave a Comment

Filed under Android, programming