Reputation: 151
I have a google map in my project. First of all, I check whether the user has location enabled. If the user does not have location enabled, a dialog box pops up asking them to enable location. When the user accepts this prompt, he or she is redirected to the settings page where they can enable location.
The problem is after enabling location and press back, the map remains in its previous state, i.e. does not zoom to the user's current location.
How can I solve this?
Upvotes: 0
Views: 4772
Reputation: 445
I think you should reload the map on the method onResume:
edit (i am assuming that you have declared the mGoogleMap object on class scope):
GoogleMap googleMap;
@Override
public void onResume() {
super.onResume();
if(googleMap != null){
googleMap.clear();
// add the markers just like how you did the first time
}
}
Upvotes: 1
Reputation: 1273
You have to implement LocationListener
public class FragmentMap extends SupportMapFragment implements LocationListener
{
GoogleMap mGoogleMap_;
[...]
@Override
public void onLocationChanged(Location location)
{ CameraPosition.Builder builder = CameraPosition.builder(mGoogleMap_.getCameraPosition());
builder.target(new LatLng(location.getLatitude(), location.getLongitude()));
mGoogleMap_.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build())); // CameraUpdateFactory.newLatLngZoom(...) if you need to zoom too
}
[...]
Upvotes: 0