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
0 comments:
Post a Comment