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:
http://groups.google.com/group/android-developers/browse_thread/thread/efae56c5fe5a2c55/fccf1fed0814a7ed?lnk=gst&q=locationmanager+network#fccf1fed0814a7ed
http://developer.android.com/reference/android/location/LocationManager.html
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$
0 comments:
Post a Comment