Identify GPS is enabled or not

KarthikRamKarthikRam USMember ✭✭

Dear Team,

I would like to place a prompt where it identifies if user has disabled GPS or not. If GPS is enabled, I would like to open a page. If its disbaled, I would like to show a prompt to tell user to enable GPS and then open. Please let me know how to acheive the same

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you have to do this with DependencyService.

    For Example, this code should test if GPS is enabled, otherwise open the panel to enable it

    (For Android)

    public class Gps : IGps
    {
        public Gps ()
        {
        }
    
        public void View(){
            LocationManager locationManager = (LocationManager)Forms.Context.GetSystemService(Context.LocationService);
    
            if (locationManager.IsProviderEnabled(LocationManager.GpsProvider) == false)
            {
                Intent gpsSettingIntent = new Intent(Settings.ActionLocationSourceSettings);
                Forms.Context.StartActivity(gpsSettingIntent);
            }
        }
    }
    
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    for iOS I think it's not possible...

  • jackfidojackfido USMember

    I suppose because iOS has a GPS and has not providers like Android, I mean, in android providers can select if their devices has or not GPS

  • JohnHardmanJohnHardman GBUniversity mod

    @KarthikRam - I know this is an old thread, but in case you haven't implemented this yet - take a look at https://github.com/jamesmontemagno/PermissionsPlugin - the Location permission is probably what you want to check.

Sign In or Register to comment.