Reputation: 9255
I am using the following code to get the latitude and longitude. Is it fine to rely on Network Provider always?
public static String getLatitudeLongitudeString() {
LocationManager lm = (LocationManager) GlobalApplication
.getAppContext().getSystemService(Context.LOCATION_SERVICE);
Location location = lm
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location == null) {
return "";
} else {
Geocoder geocoder = new Geocoder(GlobalApplication.getAppContext());
try {
List<Address> user = geocoder.getFromLocation(
location.getLatitude(), location.getLongitude(), 1);
double lat = (double) user.get(0).getLatitude();
double lng = (double) user.get(0).getLongitude();
return lat + "," + lng;
} catch (Exception e) {
Trace.e("Failed to get latitude and longitude", e);
return "";
}
}
}
Upvotes: 1
Views: 510
Reputation: 8816
It depends as Salil mentioned on your use case. In other words, it will boil down to the granularity of the location details that you need. For example, if you are going to write a weather application, then knowing the City should be enough in most cases. If you are looking at updating the map as the user moves, then you will need fine location, ideally provided by a GPS PROVIDER.
Upvotes: 0
Reputation: 1498
Honestly it "depends". But I would say review this article and figure out what the best combination of the options is. You may want a passive provider (Froyo+) to catch some GPS updates from other apps... Also depends on what you are using it for. If its a mapping app, then you want GPS, but if its just for "you are in San Francisco" type text, then the less accurate is fine...
Upvotes: 1