How to obtain user location on Google TV

I was searching for a way to get a user’s location on the Logitech Revue but I couldn’t find anything in the google documentation for google tv.
I tried getting the location based on the network since google tv doesn’t have access to a GPS, but that didn’t work.
After searching online I finally figured out how to get the user location on the Revue.
When getting the user’s last known location from the LocationManager in android you pass in a type of location you want (such as LocationManager.NETWORK_PROVIDER).
On the google tv there isn’t currently a defined type so you pass in the string “static” to the getLastKnownLocation method.
There are some permissions you need to set in your AndroidManifest.xml so you can access the location:

<uses-feature android:name="android.hardware.location" android:required="false"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

And the code to actually get the location is:

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location loc = locationManager.getLastKnownLocation("static");

Source

Share