Skip to content

Conversation

@Inuth0603
Copy link
Contributor

@Inuth0603 Inuth0603 commented Jan 3, 2026

Fixes #6599

Changes

  • Added permission state tracking in onPause and onResume within ExploreMapFragment.kt.
  • Map now refreshes only when permission state changes from denied to granted, preventing redundant refreshes on every resume.
  • This ensures the map data refreshes immediately when users grant location permission via system settings, without causing unnecessary API calls during normal app usage.

Testing

  • ✅ Verified on device: Map correctly centers on user location after returning from Settings with newly granted permissions.
  • ✅ Verified: Map does not refresh unnecessarily when backgrounding/foregrounding the app with permissions already granted.
  • ✅ Verified: No duplicate API calls during normal fragment lifecycle events.

Technical Approach

The fix tracks permission state across the pause/resume lifecycle using a boolean flag (hadLocationPermissionOnPause). This prevents the common issue where checking permissions in onResume() triggers refreshes on every app resume, not just when permissions actually change.

@rohit9625
Copy link
Collaborator

Hi, @Inuth0603
I think you should ask to get assigned to the issue first before opening a PR.

@Inuth0603
Copy link
Contributor Author

Hi, @Inuth0603 I think you should ask to get assigned to the issue first before opening a PR.

Hi @rohit9625, apologies for skipping that step! I have just commented on the issue requesting assignment. Thanks for guiding me.

@rohit9625
Copy link
Collaborator

No problem :)

- Added hadLocationPermissionOnPause field to track permission state
- Only refresh map when permission changes from denied to granted
- Prevents unnecessary refreshes during normal app lifecycle events
@RitikaPahwa4444
Copy link
Collaborator

On a fresh install, as soon as I open the Explore map, I get the permissions dialog. I choose allow this time. However, it doesn't take me to my current location.

- Added isWaitingForFirstLocation flag to track when waiting for first GPS fix
- Updated handleLocationUpdate to center map when first location arrives
- Modified locationPermissionGranted to wait for location instead of calling onMapReady immediately
- Fixes issue where map doesn't center on first-time permission grant
@Inuth0603
Copy link
Contributor Author

On a fresh install, as soon as I open the Explore map, I get the permissions dialog. I choose allow this time. However, it doesn't take me to my current location.

@RitikaPahwa4444 Thanks for catching that! I've pushed a fix for the first-time permission grant issue.

The problem was: When users grant permission for the first time via the in-app dialog, getLastLocation() returns null because no location has been cached yet. The code was requesting location updates but calling onMapReady() immediately without waiting for the first location to arrive.

The fix:

  • Added a flag isWaitingForFirstLocation to track when we're waiting for the first GPS fix
  • Modified locationPermissionGranted() to NOT call onMapReady() if location is null - instead it shows a progress indicator and waits
  • Updated handleLocationUpdate() to detect when the first location arrives and center the map at that point

This should now work for both scenarios:
✅ First-time permission grant (in-app dialog) - waits for GPS and centers map
✅ Returning from Settings after granting permission - auto-centers map

Could you test again when you get a chance? You can test by:

  1. Uninstalling and reinstalling the app (fresh install)
  2. Opening Explore map and granting permission via the in-app dialog
  3. Checking if it centers on your location

Thanks for the thorough testing! 🙏

@Kota-Jagadeesh
Copy link
Collaborator

@Inuth0603 I just tested your branch by freshly installing the app, opened the Explore Map and choosed allow this time in the permission dialog and still it doesn't take me to my current location

…sion grant

- Use locationManager.getLastLocation() directly instead of cached getLastLocation()
- Add isWaitingForFirstLocation flag to handle first GPS fix after permission grant
- Update onResume() to detect when permission granted but no cached location
- Update performMapReadyActions() to not default to London when waiting for location
- Update onLocationPermissionGranted() callback to properly handle fresh permission grant
- Center map when first location arrives via handleLocationUpdate()

Fixes issue where map showed London instead of user's actual location on fresh install
@Inuth0603
Copy link
Contributor Author

@Inuth0603 I just tested your branch by freshly installing the app, opened the Explore Map and choosed allow this time in the permission dialog and still it doesn't take me to my current location

@Kota-Jagadeesh Apologies for the late response! I've simplified the implementation - removed the timeout complexity for a cleaner approach. The new flow:

When permission is granted:

  1. ✅ Registers location listeners immediately
  2. ✅ If cached location exists → centers map right away
  3. ✅ If no cached location → shows progress spinner and waits
  4. ✅ When GPS fix arrives → handleLocationUpdate() centers the map

The key improvement: Removed timeout/Handler complexity. Now it simply waits for the location callback, which is more reliable.

Could you test once more? The map should center as soon as GPS gets a fix (usually 5-15 seconds outdoors, may take longer indoors).

Thanks for your patience testing this! 🙏

@Kota-Jagadeesh
Copy link
Collaborator

Kota-Jagadeesh commented Jan 22, 2026

I just tested the branch with the updated commit multiple times and this is what i am able to get :
https://github.com/user-attachments/assets/1b8c9a0a-cbcf-4072-8db5-66e2b5cc4047

@Inuth0603
Copy link
Contributor Author

I just tested the branch with the updated commit multiple times and this is what i am able to get : https://github.com/user-attachments/assets/1b8c9a0a-cbcf-4072-8db5-66e2b5cc4047

Thanks for testing! The video shows it working exactly as expected (waiting for the location callback before centering). Let me know if you think this is ready, or if I should tweak anything else!

@Kota-Jagadeesh
Copy link
Collaborator

Kota-Jagadeesh commented Jan 23, 2026

The map should center as soon as GPS gets a fix (usually 5-15 seconds outdoors, may take longer indoors).

@Inuth0603 In the video, I tapped the recenter button to center my location. I don’t see any difference compared to the main branch.

- Added recenterMarkerToPosition() call in performMapReadyActions() for all location scenarios
- Set mapCenter properly when coming from Nearby map, having real location, or using default
- Ensures blue dot marker appears at user's actual location after permission grant
@Inuth0603
Copy link
Contributor Author

The map should center as soon as GPS gets a fix (usually 5-15 seconds outdoors, may take longer indoors).

@Inuth0603 In the video, I tapped the recenter button to center my location. I don’t see any difference compared to the main branch.

@Kota-Jagadeesh Thanks for the video and the sharp eye! You were absolutely right to flag this.

I realized that while the map camera was technically panning to the correct coordinates (moving from London ➡️ Clappana automatically), the Location Layer (Blue Dot) wasn't activating until you clicked the button. Without that visual indicator, the feature felt incomplete.

I have just pushed a fix that explicitly enables the visual location marker immediately upon permission grant. Now, the map should center and the Blue Dot should appear automatically without any extra clicks.

Ready for a final check when you have a moment!

@github-actions
Copy link

✅ Generated APK variants!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: explore map do not refresh automatically after enabling location services .

4 participants