Closed naweed closed 2 years ago
I ran into the same issue. I resolved it by following the docs on https://docs.microsoft.com/en-us/xamarin/essentials/geolocation but using Maui Essentials instead of Xamarin.
After modifying the MainActivity.cs within the Android platform folder it asks me for location permission.
Edit: I have not tested this for iOS yet.
repro on Android & IOS. it might be related to permission. I'm not sure how to set permission for IOS, but for android simulator, you can add following content in AndroidManifest.xml
:
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
@VincentBu or others, could you please provide a reproduction project? Because I can't seem to get this issue to show up
Hi @naweed. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
could you please provide a reproduction project? Because I can't seem to get this issue to show up
Here is the repro project: MauiApp1.zip Click on 'Get Location' button, you will get error message like this:
then, add
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
to AndroidManifest.xml
and run again, you would get the expect result:
This was a very old issue. May be there was a bug in that build. Plz close.
Description
I am not able to use GetLocationAsync in MAUI Essentials. It throws an error that "The current Activity can not be detected. Ensure that you have called Init in your Activity or Application class."
Steps to Reproduce
Run the following code:
Expected Behavior
The app should launch and ask for location permissions.
Actual Behavior
It goes into the exception block with the following error: "System.NullReferenceException: The current Activity can not be detected. Ensure that you have called Init in your Activity or Application class. at Microsoft.Maui.Essentials.Platform.GetCurrentActivity(Boolean throwOnNull)"
Basic Information
Other Info
Testing against a physical device (Samsung S20+)