Using James' GeoLocation Plugin, not returning position

KenNickersonKenNickerson USMember ✭✭✭
edited October 2016 in Xamarin.iOS

Pretty vanilla implementation of the plugin using it as follows but not getting a position:

        var locator = CrossGeolocator.Current;
        //    locator.AllowsBackgroundUpdates = true;
        locator.DesiredAccuracy = 500;
        var position = locator.GetPositionAsync(timeoutMilliseconds: 7000);

During the debug, I am seeing a status of "waiting for activation" on the position object. Is there something else needed that I am missing?

When accessing the position properties, the app hangs.

I also noticed in the output window that Xamarin.IOS.dll is 32 bit when everything else is 64-bit. Do I need to replace Xamarin.IOS.dll with a 64-bit version and if so, where can I get instruction on that, please?

Loaded assembly: /private/var/containers/Bundle/Application/C0E17203-53E6-48BB-AA4A-F3CD871A8422/SouthcoastHealthiOS.app/.monotouch-64/System.dll
Loaded assembly: /private/var/containers/Bundle/Application/C0E17203-53E6-48BB-AA4A-F3CD871A8422/SouthcoastHealthiOS.app/.monotouch-64/Mono.Dynamic.Interpreter.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/C0E17203-53E6-48BB-AA4A-F3CD871A8422/SouthcoastHealthiOS.app/.monotouch-64/System.Core.dll
Loaded assembly: /private/var/containers/Bundle/Application/C0E17203-53E6-48BB-AA4A-F3CD871A8422/SouthcoastHealthiOS.app/.monotouch-32/Xamarin.iOS.dll
Loaded assembly: /private/var/containers/Bundle/Application/C0E17203-53E6-48BB-AA4A-F3CD871A8422/SouthcoastHealthiOS.app/.monotouch-64/System.Xml.dll
Loaded assembly: /private/var/containers/Bundle/Application/C0E17203-53E6-48BB-AA4A-F3CD871A8422/SouthcoastHealthiOS.app/.monotouch-64/Xamarin.Forms.Platform.dll
Loaded assembly: /private/var/containers/Bundle/Application/C0E17203-53E6-48BB-AA4A-F3CD871A8422/SouthcoastHealthiOS.app/.monotouch-64/Xamarin.Forms.Core.dll

Best Answer

Answers

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @KenNickerson,

    There are couple notes on things to do for iOS here.

    Note* iOS 9 simulators don't seem to work.

  • KenNickersonKenNickerson USMember ✭✭✭

    John. Thank you for your help. I have followed these instructions. I am not running the simulator. I am using an ipad with IOS 9.3.5. I have tried each of the plist key and both. Still no luck. The app doesn't seem to throw an any error. It appears to be timing out. When trying to access the position object, it then terminates.

  • KenNickersonKenNickerson USMember ✭✭✭

    I am getting a Task Status on the position object of WaitingForActivation. I cannot find anything specific on that but if you have any suggestions, I am grateful. Thanks again.

  • KenNickersonKenNickerson USMember ✭✭✭

    I am seeing the following in the logs:

    Xamarin.VisualStudio.IOS.XamarinIOSPackage Information: 0 : [2016-10-21 10:15:25.2971] Aborting invocation of method Position System.Threading.Tasks.Task1:get_Result () on object System.Threading.Tasks.Task1[[Plugin.Geolocator.Abstractions.Position, Plugin.Geolocator.Abstractions, Version=3.0.4.0, Culture=neutral, PublicKeyToken=null]]

  • gdkgdk INMember ✭✭✭

    Hi, I have tried with 'await' but I am getting task cancellation exception in xamarin android project.

  • LarryKenobiLarryKenobi USMember ✭✭

    @KenNickerson said:
    Needed to build a task around the GetPositionAsync with the await option. Thanks to all who read and replied.

    What does this mean exactly? I have the same issue and all of my methods are Tasks.

  • KenNickersonKenNickerson USMember ✭✭✭

    The following is my call to get GPS location and followed by that what I have in the GPS location viewmodel: Note the Task object which is what the await is expecting

           myLocation = await geolocationviewmodel.GetCurrentLocation();
    
    
    
           public async Task<LocationSearchObject> GetCurrentLocation()
           {
               try
               {
                   var locator = CrossGeolocator.Current;
                   locator.DesiredAccuracy = 100;
    
                   LocationSearchObject search = new LocationSearchObject();
    
                   search.isAvailable = locator.IsGeolocationAvailable;
                   search.isEnabled = locator.IsGeolocationEnabled;
    
                   var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));
    
                   if (position == null)
                   {
                       search.longitude = Constants.DefaultLongitude;
                       search.latitude = Constants.DefaultLatitude;
                   }
                   else
                   {
                       search.longitude = Convert.ToDecimal(position.Longitude);
                       search.latitude = Convert.ToDecimal(position.Latitude);
                   }
                   return search;
               }
    
               catch (Exception ex)
               {
                   LocationSearchObject search = new LocationSearchObject();
                   search.longitude = Constants.DefaultLongitude;
                   search.latitude = Constants.DefaultLatitude;
                   return search;
               }
           }
    
  • JrMaciasJrMacias Member ✭✭

    hi there, sorry to interrupt your daily activities, i am using Geolocator to get the device position every time a button is pressed, i have no any problem by getting the position, but the issue i have is when i use this method multiple times, i mean, sometimes i get the exact location but most of the times i am getting a location which is more than 100 meters away...i need to get a exact location or maybe with a 10 meters error margin of error but no more...please help me with that

Sign In or Register to comment.