Bug 6167 - IsGeolocationEnabled always false
Summary: IsGeolocationEnabled always false
Status: RESOLVED INVALID
Alias: None
Product: Mobile API (Preview)
Classification: Xamarin
Component: Xamarin.iOS ()
Version: Preview
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Eric Maupin
URL:
Depends on:
Blocks:
 
Reported: 2012-07-18 04:54 UTC by Dylan
Modified: 2012-10-05 14:00 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Dylan 2012-07-18 04:54:17 UTC
On the newly released version (0.5) when I want to use location for the first time I do not get a message asking if the app can use the location services on iPhone. Therefore the IsGeolocationEnabled is always false.
Comment 1 Eric Maupin 2012-07-19 14:20:49 UTC
The current design really doesn't handle this very well, so I'm looking into adjusting it to make more sense. For the moment, you can also simply call GetPositionAsync or StartListening, which will trigger the permission request. You'll get a GeolocationException or the PositionError event will fire (respectively) should permission be (or still be) denied.
Comment 2 Eric Maupin 2012-10-05 14:00:55 UTC
After further review, we feel that this is the correct behavior. We'll be updating the docs to clarify things better, but in the mean time I'll explain.

IsGeolocationEnabled is meant to represent that you can start listening for location right now and it'll work. If the user hasn't been asked yet, that isn't true, therefore it is false.

There are two primary category of apps, those that require location (like a running app) and those that don't (a photo app, giving you the option to geotag photos). For the former, you will always need location, so you can simply start listening and you'll get the same error you expect.

For apps that have optional support, we suggest keeping track of whether you've prompted the user for locations already:

if (!alreadyAsked || geolocator.IsGeolocationEnabled)
{
    geolocator.StartListening(..);
    alreadyAsked = true; // Persist this
}

This will allow you to prompt the user only once (as per Apple's guidelines) and will Just Work if they've already said yes (or are on Android or Windows Phone), and won't do anything if they've disabled geolocation completely or for the app.