Reputation: 14370
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?
Upvotes: 2
Views: 3109
Reputation: 6023
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..
Upvotes: 1
Reputation: 30934
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.
Upvotes: 0