Forum Xamarin.Forms

PopUp Location

Hi,
I am trying to implement the google popup for the location but unfortunately the method I found has been deprecated. More precisely googleapiclient and locationservices are deprecated
I can't figure out how to update it. Below is the code

public async void turnOnGPS()
        {
            try
            {
                MainActivity activity = Forms.Context as MainActivity;

                GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
                    .AddApi(LocationServices.API).Build();
                googleApiClient.Connect();
                LocationRequest locationRequest = LocationRequest.Create();
                locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
                locationRequest.SetInterval(10000);
                locationRequest.SetFastestInterval(10000 / 2);

                LocationSettingsRequest.Builder
                        locationSettingsRequestBuilder = new LocationSettingsRequest.Builder()
                        .AddLocationRequest(locationRequest);
                locationSettingsRequestBuilder.SetAlwaysShow(false);
                LocationSettingsResult locationSettingsResult = await LocationServices.SettingsApi.CheckLocationSettingsAsync(
                    googleApiClient, locationSettingsRequestBuilder.Build());

                if (locationSettingsResult.Status.StatusCode == LocationSettingsStatusCodes.ResolutionRequired)
                {
                    locationSettingsResult.Status.StartResolutionForResult(activity, 0);
                }
            }
            catch (Exception)
            {

            }
        }


Answers

  • YelinzhYelinzh Member, Xamarin Team Xamurai

    More precisely googleapiclient and locationservices are deprecated

    The LocationServices api seems not be deprecated. Do you mean the SettingsApi? If so, try using SettingsClient instead. The SettingsClient class also provide the
    checkLocationSettings method.

     Task<LocationSettingsResponse> result =
             LocationServices.getSettingsClient(this).checkLocationSettings(builder.build());
    

    Check the doc:
    https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • DavidSpecterDavidSpecter Member ✭✭
    edited February 22

    I'm working on API 29 and this is the alert of Visual Studio.

    Davide.

  • YelinzhYelinzh Member, Xamarin Team Xamurai

    As the screenshot shows, the SettingsApi is obsoleted. You could use the SettingsClient class instead.

    The LocationServices.getSettingsClient(this).checkLocationSettings method doesn't requires a GoogleApiClient parameter.

Sign In or Register to comment.