Forum Cross Platform with Xamarin

Not able to access current location by geolocator in IOS.

abhay27abhay27 Member ✭✭


I want to access current location's long lat so i am doing it by geo locator but it not coming.
my code is as below:

    public async void GetCurrentLocation()

                     var locator = CrossGeolocator.Current;
                        locator.DesiredAccuracy = 50;
                     var position = await locator.GetPositionAsync(timeout: TimeSpan.FromMilliseconds(10000));

                        activityMainData.Longitude = position.Longitude.ToString();

                        activityMainData.Latitude = position.Latitude.ToString();

                        activityMainData.Altitude = position.Altitude.ToString();

                catch (Exception ex)
                throw ex;

I have give Permission as below:

    Location Always Usage Description

but i am not getting current long lat
please help me ASAP.Thanks in Advance

Best Answer


  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai


    That code looks fine so I do not know why you are not getting the position data. Are you testing on device or simulator?

  • abhay27abhay27 Member ✭✭

    @JGoldberger Simulator

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai


    I have seen some issues with the simulator and getting single shot locations. I get the location the first time a button that launches code like what you have above is clicked, but if I then change the simulator location and click the button again, the location does not get updated every time. It seems partially due to the desired accuracy setting. Try lowering desired accuracy to 10, though with a setting of 1 I never get the location.

    Anyway, it seems kind of hit or miss on the simulator. Testing location on device seems more reliable. Are you never getting a location? Or is it just intermittent?

    If you listen for location changes, things seem to happen more reliably on the simulator. I have attached a sample that listens for changes, and also has a button to get the current location. Let me know if this helps you resolve this issue.

    The iOS CLLocationManager class, which the plugin uses behind the scenes for iOS, also makes some decisions about whether to deliver a new location based on the desired accuracy, time since last location update, etc. It's kind of a black box, but read up on it here:

  • abhay27abhay27 Member ✭✭
    edited June 2018

    Every thing is working Fine in Device but issue is in simulator.

    and it not displaying even a single time and showing error as unavailable location.

Sign In or Register to comment.