Plugin.Geolocator.Abstractions.IGeolocator.Getpositionasync Indexoutofrangeexception

Asked

Viewed 41 times

0

I’m using Xamarin.Forms and trying to get the position with the Plugin.Geolocator and Getpositionasync method falls into an exception of Indexoutofrangeexception

        var locator = CrossGeolocator.Current;

        CancellationToken cancellation = new CancellationToken(false);

        locator.DesiredAccuracy = 1;

        if (!CrossGeolocator.IsSupported)
            position = new Position();
        if (!CrossGeolocator.Current.IsGeolocationEnabled)
            position = new Position();
        if (!CrossGeolocator.Current.IsGeolocationAvailable)
            position = new Position();

        try
        {
            position = await locator.GetPositionAsync(TimeSpan.FromTicks(1), cancellation, true);
        }
        catch (Exception e)
        {
            position = new Position();
        }


System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at (wrapper stelemref) System.Object.virt_stelemref_object(intptr,object)
  at <StartupCode$NInterpret-Xamarin-Droid>.$Interpreter.push@3149 (NInterpret.Interpreter this, System.Collections.Generic.Stack`1[T] callStack, System.Object x) [0x00028] in <5b4cad727eef0f2aa745038372ad4c5b>:0 
  at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet`1[T] inTries, Microsoft.FSharp.Core.FSharpOption`1[T] lastException) [0x00225] in <5b4cad727eef0f2aa745038372ad4c5b>:0 
  at NInterpret.Interpreter.interpret (System.Object[] args) [0x00098] in <5b4cad727eef0f2aa745038372ad4c5b>:0 
  at NInterpret.Interpreter.callAMethod (NInterpret.AMethod m, NInterpret.AType[] ptypes, NInterpret.AType[] genericMethodArgs, System.Collections.Generic.Dictionary`2[TKey,TValue] genericArgsIndex, System.Object[] args, System.Collections.Generic.List`1[T] byRefArgs, Microsoft.FSharp.Core.FSharpOption`1[T] byRefTarget, System.Object target, System.Boolean virtualCall) [0x00183] in <5b4cad727eef0f2aa745038372ad4c5b>:0 

Hug and Thanks

  • Where is the statement of position, what are the grounds of GetPositionAsync() and its type of return. You are sure the error is in this code snippet?

  • Hello Leandro, all right? getPositionAsync is without parameters and the return is Position. Position position; Crossgeolocator.Current.Desiredaccuracy = 100; Try { position = await Crossgeolocator.Current.Getionapositsync(); } catch (Exception e) { Debug.Writeline(e); position = new Position(); }

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.