Skip to content Skip to sidebar Skip to footer

Need A Better Way For Current Location

Through nearly all problems/answers here and on the web, the best way for current location is as follows: if ( mLocationManager==null ) mLocationManager = (LocationManager) get

Solution 1:

Try this: GoogleMap googleMap;

googleMap.setMyLocationEnabled(true);//Inside on create()

May this help you!!!

Solution 2:

Why do you call mLocationManager.requestLocationUpdates(provider, 1000, 1, locationListener); before mLocationManager.getLastKnownLocation(provider);? As far as I know, requestLocationUpdates will register a listener that will keep notifying you of the phone's location. getLastKnownLocation() will give you the last known location for the provider. So the two are to accomplish different things.

If you just want one instance of the current location, get rid of requestLocationUpdates(). Then, you need to check if the current best location as per your code above is good enough. If it is not, you can request a single update later (outside your for loop): locationManager.requestSingleUpdate(criteria, singleUpdatePI);

Also note that you can only get location from the providers if the user has authorized so in the settings. In Android 4+, "Location access" settings explicitly request for authorization to:

Let apps use Google's location service to estimate your location faster.

Post a Comment for "Need A Better Way For Current Location"