Friday, May 15, 2009

Permissions Journey: ACCESS_COARSE_LOCATION

While having problems on ACCESS_CHECKIN_PROPERTIES permission, i decided to journey to ACCESS_COARSE_LOCATION first. Some of you might ask what's the difference between ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION. ACCESS_COARSE_LOCATION is network based location access meaning the location is by your network, it could work with buildings or underground trains as long as you have access to your network while ACCESS_FINE_LOCATION is using gps thus your phone needs to be united with the sky (Correct me if im wrong here).

Now to our code (Tested this on the phone not on emulator).
Add In Manifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
In Main.java
LocationManager m_location_manager = (LocationManager) getSystemService(LOCATION_SERVICE);
Location lm = m_location_manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Log.d("log",lm.toString());


Explanation
The first line get our system service and the second line would get the last know location based on the network provider.

* Please take note that this assumes that it has a last known location, in order to know have location please see the function requestLocationUpdates.

References:
Google Groups
LocationManager in developer.andriod.com
http://www.google.com/codesearch/p?hl=en#Dgfu4syu6ZY/trunk/src/info/yasskin/droidmuni/DroidMuni.java&q=ACCESS_COARSE_LOCATION
http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/location/java/android/location/LocationManager.java&q=file:%28/|^%29android/location/LocationManager\.java$

Update History
   Jan 17, 2012 - Visual Update
Post a Comment