getLastKnownLocation() may not have values, if nothing is causing the device to go find locations. You should consider using requestLocationUpdates() to get the device to figure out where you are.
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 > -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android 2.3 Programming Books: http://commonsware.com/books -- 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

