But doesn't the device always know where it is - assuming it has a GPS,
WiFi or network connection?

Other than getLastKnownLocation() is my code a reasonable paradigm for
getting the best available location fix?

>>>>> "MM" == Mark Murphy <[email protected]> writes:

   MM> getLastKnownLocation() may not have values, if nothing is causing
   MM> the device to go find locations. You should consider using
   MM> requestLocationUpdates() to get the device to figure out where
   MM> you are.

   MM> On Fri, Feb 18, 2011 at 9:51 AM, Jake Colman <[email protected]> wrote:
   >> 
   >> My app needs to determine the current location. áI'd like the best
   >> location that is available but can live with a coarse location. áI
   >> configured the app to request ACCESS_COARSE_LOCATION permission.
   >> Everything seems to work fine for me on my HTC EVO but a Droid 2 user
   >> says that the app cannot determine location even though Google is able
   >> to. áThat user has his GPS activated and, since it's a phone, his
   >> network is active as well.
   >> 
   >> This is the code I am using for determining location:
   >> 
   >> private Location getLocation() {
   >> áString provider = "fake";
   >> áLocation l = new Location(provider);
   >> áLocationManager lm = (LocationManager) context
   >> á á á á.getSystemService(Context.LOCATION_SERVICE);
   >> áif (lm == null) {
   >> á áLog.e("AndroidGeoLocation", "No location manager?!?");
   >> á álocationWasDetermined = false;
   >> á áreturn l;
   >> á}
   >> áList<String> providers = lm.getProviders(true);
   >> áif (null == providers) {
   >> á áLog.e("AndroidGeoLocation", "No providers?!?");
   >> á álocationWasDetermined = false;
   >> á áreturn l;
   >> á}
   >> á/*
   >> á * Loop over the array backwards, and if you get an accurate 
location,then
   >> break
   >> á * out the loop
   >> á */
   >> áfor (int i = providers.size() - 1; i >= 0; i--) {
   >> á ál = lm.getLastKnownLocation(providers.get(i));
   >> á áif (l != null) {
   >> á á ábreak;
   >> á á}
   >> á}
   >> 
   >> áif (l != null)
   >> á álocationWasDetermined = true;
   >> áelse
   >> á áLog.e("AndroidGeoLocation", "No accurate location?!?");
   >> áreturn l;
   >> }
   >> 
   >> Am I doing something wrong here? áShould I be requesting
   >> ACCESS_FINE_LOCATION instead of ACCESS_COARSE_LOCATION?
   >> 
   >> Thanks.
   >> 
   >> ...Jake
   >> 
   >> 
   >> --
   >> Jake Colman -- Android Tinkerer
   >> 
   >> --
   >> You received this message because you are subscribed to the Google
   >> Groups "Android Developers" group.
   >> To post to this group, send email to [email protected]
   >> To unsubscribe from this group, send email to
   >> [email protected]
   >> For more options, visit this group at
   >> http://groups.google.com/group/android-developers?hl=en
   >> 

   MM> -- 
   MM> Mark Murphy (a Commons Guy)
   MM> http://commonsware.com | http://github.com/commonsguy
   MM> http://commonsware.com/blog | http://twitter.com/commonsguy

   MM> Android 2.3 Programming Books: http://commonsware.com/books

   MM> -- 
   MM> You received this message because you are subscribed to the Google
   MM> Groups "Android Developers" group.
   MM> To post to this group, send email to [email protected]
   MM> To unsubscribe from this group, send email to
   MM> [email protected]
   MM> For more options, visit this group at
   MM> http://groups.google.com/group/android-developers?hl=en

-- 
Jake Colman -- Android Tinkerer

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to