Xamarin.Mobile.dll

Hi is anyone able to fetch GeoLocations using Xamarin.Mobile.dll? can you post a sample code here? I mean I don't want the co-ordinates from the Activity Class.. I Just need a plugin Class which Can give me the location Co-Ordinates so I can use Interface and access on my MVVM

Best Answer

Answers

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Scorpian1990 - I am going to assume this question is no longer relevant because you found the GeoLocator plugin https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Geolocator

  • MikeDennisMikeDennis USMember ✭✭

    Hey @AdamP the example doesn't work, can you point me a short example other than that or with the code change?

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Scorpian1990 - do you have the correct permissions selected in your Android app? As per the link above (near the bottom of the page)

  • MikeDennisMikeDennis USMember ✭✭
    edited January 2016

    @AdamP : Yes I have Added the permissions. can you share me some sample App which just fetches the location and returns the location to the portable class interface whenever the method is called in android?

  • MikeDennisMikeDennis USMember ✭✭
    edited January 2016

    @AdamP:
    I did the following steps:
    1. Added Xamarin.mobile.dll on my portable, .Droid projects
    2. Added these Permission to the device
    "android.permission.ACCESS_COARSE_LOCATION"
    "android.permission.ACCESS_FINE_LOCATION"
    3. Added the following code in the method calling function on portable project:
    var locator = CrossGeolocator.Current;
    locator.DesiredAccuracy = 50;

                var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
    
    
                Result = position.ToString();
    

    4. While Calling the method got this error:
    01-09 02:15:32.910 I/MonoDroid(20677): UNHANDLED EXCEPTION:
    01-09 02:15:32.912 I/MonoDroid(20677): System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
    01-09 02:15:32.912 I/MonoDroid(20677): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
    01-09 02:15:32.912 I/MonoDroid(20677): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (object) [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1006
    01-09 02:15:32.912 I/MonoDroid(20677): at Android.App.SyncContext/c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
    01-09 02:15:32.912 I/MonoDroid(20677): at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
    01-09 02:15:32.912 I/MonoDroid(20677): at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Lang.IRunnable.cs:71
    01-09 02:15:32.912 I/MonoDroid(20677): at (wrapper dynamic-method) object.d1533d09-d216-4177-aaa5-ce669817aa00 (intptr,intptr)
    01-09 02:15:32.917 W/art (20677): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
    01-09 02:15:32.919 D/AndroidRuntime(20677): Shutting down VM
    An unhandled exception occured.

    01-09 02:15:37.378 E/AndroidRuntime(20677): FATAL EXCEPTION: main
    01-09 02:15:37.378 E/AndroidRuntime(20677): Process: Tutorial.Droid, PID: 20677
    01-09 02:15:37.378 E/AndroidRuntime(20677): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    01-09 02:15:37.378 E/AndroidRuntime(20677): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:726)
    01-09 02:15:37.378 E/AndroidRuntime(20677): Caused by: java.lang.reflect.InvocationTargetException
    01-09 02:15:37.378 E/AndroidRuntime(20677): at java.lang.reflect.Method.invoke(Native Method)
    01-09 02:15:37.378 E/AndroidRuntime(20677): at java.lang.reflect.Method.invoke(Method.java:372)
    01-09 02:15:37.378 E/AndroidRuntime(20677): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:931)
    01-09 02:15:37.378 E/AndroidRuntime(20677): ... 1 more
    01-09 02:15:37.378 E/AndroidRuntime(20677): Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
    01-09 02:15:37.378 E/AndroidRuntime(20677): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
    01-09 02:15:37.378 E/AndroidRuntime(20677): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (object) [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1006
    01-09 02:15:37.378 E/AndroidRuntime(20677): at Android.App.SyncContext/c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
    01-09 02:15:37.378 E/AndroidRuntime(20677): at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
    01-09 02:15:37.378 E/AndroidRuntime(20677): at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Lang.IRunnable.cs:71
    01-09 02:15:37.378 E/AndroidRuntime(20677): at (wrapper dynamic-method) object.d1533d09-d216-4177-aaa5-ce669817aa00 (intptr,intptr)
    01-09 02:15:37.378 E/AndroidRuntime(20677):
    01-09 02:15:37.378 E/AndroidRuntime(20677): at mono.java.lang.RunnableImplementor.n_run(Native Method)
    01-09 02:15:37.378 E/AndroidRuntime(20677): at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
    01-09 02:15:37.378 E/AndroidRuntime(20677): at android.os.Handler.handleCallback(Handler.java:739)
    01-09 02:15:37.378 E/AndroidRuntime(20677): at android.os.Handler.dispatchMessage(Handler.java:95)
    01-09 02:15:37.378 E/AndroidRuntime(20677): at android.os.Looper.loop(Looper.java:135)
    01-09 02:15:37.378 E/AndroidRuntime(20677): at android.app.ActivityThread.main(ActivityThread.java:5238)
    01-09 02:15:37.378 E/AndroidRuntime(20677): ... 4 more

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Scorpian1990 - The error message is saying you need to install the NuGet package on your Android project.

    You mention you add Xamarin.Mobile to your apps. I would not go with any direct DLL reference. I would remove all of that and install this NuGet package

    https://www.nuget.org/packages/Xam.Plugin.Geolocator

    On both your PCL and Native Droid project.

  • MikeDennisMikeDennis USMember ✭✭

    @AdamP thanks a lot man ... It works,but it crashes when GPS is disabled.. is there any inbuilt function to check for the GPS status?

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Scorpian1990 - make sure these are both true before proceeding, otherwise inform the user to turn them on.

    locator.IsGeolocationAvailable
    locator.IsGeolocationEnabled
    
  • MikeDennisMikeDennis USMember ✭✭

    Thanks a lot dude :)

  • MikeDennisMikeDennis USMember ✭✭

    @AdamP : Do you have any working sample's of xamarin PCL project with OSM Navigation? or any head sup on the same?,
    basically i am trying to create a map navigation using xamarina and OSM

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Scorpian1990 - sorry, I haven't done OSM Navigation before.

  • MikeDennisMikeDennis USMember ✭✭

    Ok thanks.

  • MikeDennisMikeDennis USMember ✭✭

    @AdamP Application Crashed on second Time when I request for the location:

    Scenario:
    1.I have a list of Online Radio Station available
    2. When User select's any Radio Station then I will request for location on my viewModel and process it{added the function below which will hit when ever I select any option in the list}
    3. When User select's first time it fetches the location but when he selects the second station App crashes with the following status
    Code:
    {
    var locator = CrossGeolocator.Current;
    locator.DesiredAccuracy = 50;
    var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
    var latitude = position.Latitude;
    var longitude = position.Longitude;
    }

    Trace:
    02-12 16:35:27.028 I/MonoDroid(20070): UNHANDLED EXCEPTION:
    02-12 16:35:27.058 I/MonoDroid(20070): System.Threading.Tasks.TaskCanceledException: A task was canceled.
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:193
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:580 02-12 16:35:27.058 I/MonoDroid(20070): at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in G:\GitHub\Xamarin.Plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:195 02-12 16:35:27.058 I/MonoDroid(20070): --- End of stack trace from previous location where exception was thrown --- 02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:190 02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372
    02-12 16:35:27.058 I/MonoDroid(20070): at Online.Radio.Core.Forms.ViewModels.OnlineCurrentLocation+d__23.MoveNext () [0x00192] in C:\Users\mike dennis\Documents\GitHub\online-mike\UI\Online.Radio\Online.Radio\Forms\ViewModels\OnlineCurrentLocation.cs:95
    02-12 16:35:27.058 I/MonoDroid(20070): --- End of stack trace from previous location where exception was thrown ---
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:190
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372
    02-12 16:35:27.058 I/MonoDroid(20070): at Online.Radio.Core.Pages.Content.SelectLocationPage+d__13.MoveNext () [0x00114] in C:\Users\mike dennis\Documents\GitHub\online-mike\UI\Online.Radio\Online.Radio\Pages\Content\SelectLocationPage.xaml.cs:51
    02-12 16:35:27.058 I/MonoDroid(20070): --- End of stack trace from previous location where exception was thrown ---
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
    02-12 16:35:27.058 I/MonoDroid(20070): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:994
    02-12 16:35:27.058 I/MonoDroid(20070): at Android.App.SyncContext+c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
    02-12 16:35:27.058 I/MonoDroid(20070): at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
    02-12 16:35:27.058 I/MonoDroid(20070): at Java.Lang.IRunnableInvoker.n_Run (IntPtr jnienv, IntPtr native__this) [0x00009] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Lang.IRunnable.cs:71
    02-12 16:35:27.058 I/MonoDroid(20070): at (wrapper dynamic-method) System.Object:3bb53503-1439-4f26-a91f-dbdecee6ea9b (intptr,intptr)
    An unhandled exception occured.

    02-12 16:35:27.908 E/mono (20070):
    02-12 16:35:27.908 E/mono (20070): Unhandled Exception:
    02-12 16:35:27.908 E/mono (20070): System.Threading.Tasks.TaskCanceledException: A task was canceled.
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:193
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:580 02-12 16:35:27.908 E/mono (20070): at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in G:\GitHub\Xamarin.Plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:195 02-12 16:35:27.908 E/mono (20070): --- End of stack trace from previous location where exception was thrown --- 02-12 16:35:27.908 E/mono (20070): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:190 02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372
    02-12 16:35:27.908 E/mono (20070): at Online.Radio.Core.Forms.ViewModels.OnlineCurrentLocation+d__23.MoveNext () [0x00192] in C:\Users\mike dennis\Documents\GitHub\online-mike\UI\Online.Radio\Online.Radio\Forms\ViewModels\OnlineCurrentLocation.cs:95
    02-12 16:35:27.908 E/mono (20070): --- End of stack trace from previous location where exception was thrown ---
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:190
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    02-12 16:35:27.908 E/mono (20070): at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/ In mgmain JNI_OnLoad 02-12 16:35:27.908 E/mono-rt (20070): [ERROR] FATAL UNHANDLED EXCEPTION: System.Threading.Tasks.TaskCanceledException: A task was canceled. 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:193 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:580
    02-12 16:35:27.908 E/mono-rt (20070): at Plugin.Geolocator.GeolocatorImplementation+d__27.MoveNext () [0x00597] in G:\GitHub\Xamarin.Plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:195
    02-12 16:35:27.908 E/mono-rt (20070): --- End of stack trace from previous location where exception was thrown ---
    02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
    02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:190
    02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372 02-12 16:35:27.908 E/mono-rt (20070): at Online.Radio.Core.Forms.ViewModels.OnlineCurrentLocation+<updateLocationEvent>d__23.MoveNext () [0x00192] in C:\Users\mike dennis\Documents\GitHub\online-mike\UI\Online.Radio\Online.Radio\Forms\ViewModels\OnlineCurrentLocation.cs:95 02-12 16:35:27.908 E/mono-rt (20070): --- End of stack trace from previous location where exception was thrown --- 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:190 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 02-12 16:35:27.908 E/mono-rt (20070): at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in

  • MikeDennisMikeDennis USMember ✭✭

    @JamesMontemagno : Any guess on why the App crashes with the above error?

  • MikeDennisMikeDennis USMember ✭✭

    @AdamP Any guess on why the App crashes with the above error?

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    If it times out it throws an exceptio. You need to try catch it.

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @MikeDennis - what James said :) It looks like a timeout, or at least if you catch it, then you might have a better exception message.

  • SgXam15SgXam15 INMember ✭✭

    Hi,@AdamP I am stuck with similar problem.I used the following geolocator:

    https://www.nuget.org/packages/Xam.Plugin.Geolocator

    in my app.I also did set the permissions for android,IOS as mentioned. Everytime I tried accessing my devices location the app crashed.I tried catching the exception.The error stack is as follows:

    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36
    Thread finished: #3
    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36
    Thread started: #8
    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36

    My code snippet is as follows:

    private async void LocationRequest(object sender, EventArgs e)
    {

            var locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;
            try
            {
                if (locator.IsGeolocationEnabled && locator.IsGeolocationAvailable)
                {
                    var position = await locator.GetPositionAsync(timeoutMilliseconds: 1000000);
                    await DisplayAlert("", "Please enter a valid email address", "OK");
    
                    Debug.WriteLine("Position Status: {0}", position.Timestamp);
                    Debug.WriteLine("Position Latitude: {0}", position.Latitude);
                    Debug.WriteLine("Position Longitude: {0}", position.Longitude);
    
                }
                }
            catch (Exception S)
            {
                System.Diagnostics.Debug.WriteLine("Error : {0}", S);
            }
        }
    

    Kindly apprise me about my code flaws or if I am missing anything to get the implementation working.

  • SgXam15SgXam15 INMember ✭✭

    Hi,@MikeDennis,@AdamP I am stuck with similar problem.I used the following geolocator:

    https://www.nuget.org/packages/Xam.Plugin.Geolocator

    in my app.I also did set the permissions for android,IOS as mentioned. Everytime I tried accessing my devices location the app crashed.I tried catching the exception.The error stack is as follows:

    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36
    Thread finished: #3
    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36
    Thread started: #8
    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36

    My code snippet is as follows:

    For IOS:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using CoreLocation;
    using Foundation;
    using UIKit;

    namespace MyProj.iOS
    {
    public class Application
    {
    static void Main (string[] args)
    {

            var manager = new CLLocationManager();
    
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                manager.RequestWhenInUseAuthorization();
    
            UIApplication.Main (args, null, "AppDelegate");
        }
    }
    

    }

    A baseclass in xamarin.forms:

    using System;
    using Xamarin.Forms;
    using System.Collections.Generic;
    using Rg.Plugins.Popup.Extensions;
    using Plugin.Geolocator;
    using System.Diagnostics;

    private async void LocationRequest(object sender, EventArgs e)
    {
    var locator = CrossGeolocator.Current;
    locator.DesiredAccuracy = 50;
    try
    {
    if (locator.IsGeolocationEnabled && locator.IsGeolocationAvailable)
    {
    var position = await locator.GetPositionAsync(timeoutMilliseconds: 1000000);
    await DisplayAlert("", “Positiions are on your screen:", "OK");

                    Debug.WriteLine("Position Status: {0}", position.Timestamp);
                    Debug.WriteLine("Position Latitude: {0}", position.Latitude);
                    Debug.WriteLine("Position Longitude: {0}", position.Longitude);
    
                }
                }
            catch (Exception S)
            {
                System.Diagnostics.Debug.WriteLine("Error : {0}", S);
            }
        }
    

    Kindly help me resolve this.I want to get a dialog box with locations specified and also a prompt that would ask the user for its GPS access.

  • SgXam15SgXam15 INMember ✭✭

    Hi,@MikeDennis,@AdamP I am stuck with similar problem.I used the following geolocator:

    https://www.nuget.org/packages/Xam.Plugin.Geolocator

    in my app.I also did set the permissions for android,IOS as mentioned. Everytime I tried accessing my devices location the app crashed.I tried catching the exception.The error stack is as follows:

    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36
    Thread finished: #3
    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36
    Thread started: #8
    Error : System.Threading.Tasks.TaskCanceledException: A task was canceled.
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
    at MyProj.Friend_3+c__async0.MoveNext () [0x000d8] in /Users/sagarsaxena/Projects/MyProj/MyProj/Friend_3.cs:36

    My code snippet is as follows:

    For IOS:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using CoreLocation;
    using Foundation;
    using UIKit;

    namespace MyProj.iOS
    {
    public class Application
    {
    static void Main (string[] args)
    {

            var manager = new CLLocationManager();
    
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                manager.RequestWhenInUseAuthorization();
    
            UIApplication.Main (args, null, "AppDelegate");
        }
    }
    

    }

    A baseclass in xamarin.forms:

    using System;
    using Xamarin.Forms;
    using System.Collections.Generic;
    using Rg.Plugins.Popup.Extensions;
    using Plugin.Geolocator;
    using System.Diagnostics;

    private async void LocationRequest(object sender, EventArgs e)
    {
    var locator = CrossGeolocator.Current;
    locator.DesiredAccuracy = 50;
    try
    {
    if (locator.IsGeolocationEnabled && locator.IsGeolocationAvailable)
    {
    var position = await locator.GetPositionAsync(timeoutMilliseconds: 1000000);
    await DisplayAlert("", “Positiions are on your screen:", "OK");

                    Debug.WriteLine("Position Status: {0}", position.Timestamp);
                    Debug.WriteLine("Position Latitude: {0}", position.Latitude);
                    Debug.WriteLine("Position Longitude: {0}", position.Longitude);
    
                }
                }
            catch (Exception S)
            {
                System.Diagnostics.Debug.WriteLine("Error : {0}", S);
            }
        }
    

    Kindly help me resolve this.I want to get a dialog box with locations specified and also a prompt that would ask the user for its GPS access.

Sign In or Register to comment.