How to obtain Latitude and longitude from the mobile device if GPS is not available... My mobile has internet Connection through wifi and gprs connection.... Can we get the lats and long from this?
Asked
Active
Viewed 3,088 times
2
-
1Ave you read the Android Dev Guide article to the topic? http://developer.android.com/guide/topics/location/obtaining-user-location.html – RoToRa Mar 31 '11 at 08:22
2 Answers
1
edited : Network and also GPS Provider Location
Yes we cam...try this
LocationManager manager = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE);
manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
// additionally (you have to implement LocationListener)
manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0.0f, new LocationListener() ...)
After location you can use in locationlistener...
@Override
public void onLocationChanged(Location location) {
Log.d("a","onLocationChanged: lat="+location.getLatitude());
Log.d("a","onLocationChanged: lat="+location.getLongitude());
}
hope it helps..
-
Hello Uday,i used your code and included the implemented methods of locationlistener and i Tried Logging in all the unimplemented methods..but my code doest go inside any of the methods.... My Mobile just has wifi enabled....HTC WIldfire 2.2 Froyo.... – coderslay Apr 01 '11 at 06:44
-
I am not getting the coordinates... Is there some other way to obtain coordinates without using Locationmanager? – coderslay Apr 02 '11 at 04:42
-
I got the coordinates by GPS but when i use NETWORK_PROVIDER then my tablet shows me that there is no provider available(while wifi is available on tablet)... and my android mobile doesnt show anything(it doesnt override any of the functions)....... – coderslay Apr 02 '11 at 05:31
0
Yes you can. Have a look at the documentation
When you have a Location from the system. you can use methods getLongitude() and getLatitude()
For a full example have a look at this code - lines 122-124 to set up receiving updates and lines 201-209 to get the Location.

Heiko Rupp
- 30,426
- 13
- 82
- 119
-
Hello Heiko... i used ur code like Location location = getCurrentLocation(); which calls the getCurrentLocation(); and through this i am getting location value as null...i just have wifi enabled on my mobile... – coderslay Apr 01 '11 at 06:23
-
Did you also start receiving location updates - as set up in lines 122-124 and as @Udaykiran has indicated in its first source listing in his answer? – Heiko Rupp Apr 01 '11 at 07:43
-
I got the coordinates by GPS but when i use NETWORK_PROVIDER then my tablet shows me that there is no provider available(while wifi is available on tablet)... and my android mobile doesnt show anything(it doesnt override any of the functions)....... – coderslay Apr 02 '11 at 05:32