smart-location-lib icon indicating copy to clipboard operation
smart-location-lib copied to clipboard

Add google location dialog

Open danponce opened this issue 7 years ago • 6 comments

This library is great! It simplifies a lot the code for getting locations, so thanks! Now, to show the dialog (same as the Google Maps dialog) that turns the GPS on, the library needs to use LocationSettingsRequest.Builder and use the method setAlwaysShow(true). Can you add this option please?

danponce avatar Aug 27 '17 02:08 danponce

@mrmans0n It would be really helpful if you add this option too.. Thanks in advance

saeedjassani avatar Sep 17 '17 03:09 saeedjassani

+1

putrabangga avatar Nov 28 '17 05:11 putrabangga

That option is provided.

provider = new LocationGooglePlayServicesProvider(); provider.setCheckLocationSettings(true);

araiyusuke avatar Jan 19 '18 08:01 araiyusuke

@araiyusuke thanks for your suggestion, it shows the dialog indeed. But the location itself is not fetched, the callback is not fired. Here is my code:

SmartLocation
                .with(this)
                .location(LocationGooglePlayServicesProvider().apply { setCheckLocationSettings(true) })
                .start {
            Timber.e(it.toString())
        }

If GPS is already enabled and it doesn't need to show the dialog, it works normally. Any info on that?

Ornolfr avatar Feb 22 '18 18:02 Ornolfr

@araiyusuke thanks for your suggestion, it shows the dialog indeed. But the location itself is not fetched, the callback is not fired. Here is my code:

SmartLocation
                .with(this)
                .location(LocationGooglePlayServicesProvider().apply { setCheckLocationSettings(true) })
                .start {
            Timber.e(it.toString())
        }

If GPS is already enabled and it doesn't need to show the dialog, it works normally. Any info on that?

Hey I was experiencing the same problem, but then found out the solution. It's there in the log, saying that you will get your callback in your Activity's callback. Then you need to call the provider's onActivityResult to continue the flow or probably just start requesting location again.

LocationGooglePlayServicesProvider.this.logger.w("Location settings are not satisfied. Show the user a dialog to upgrade location settings. You should hook into the Activity onActivityResult and call this provider's onActivityResult method for continuing this call flow. ", new Object[0]);

luthfihariz avatar Dec 07 '18 00:12 luthfihariz

Basically you can not show Location Settings if not init SmartLocation using Activity Context, because the Dialog only show if context is instance of Activity as shown below..

if (context instanceof Activity) { try { // Show the dialog by calling startResolutionForResult(), and check the result // in onActivityResult(). status.startResolutionForResult((Activity) context, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { logger.i("PendingIntent unable to execute request."); } } else { logger.w("Provided context is not the context of an activity, therefore we can't launch the resolution activity."); }

This snippet from https://github.com/mrmans0n/smart-location-lib/blob/master/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java

RazibKani avatar Feb 13 '19 05:02 RazibKani