Blazor Hybrid WebView not able to Obtain GPS Location
See original GitHub issueDescription
I have created RCL Project which uses GoogleMap. This is purely done in Javascript/HTM/css using google maps Javascript SDK. I am trying to use this RCL in Blazor Hybrid Project. It does load the Map, but Location is denied.

Not sure if this was needed but i also entered the permission for android platform in AndroidManifest.xml, that did not help either.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
Is there anything else that i need to do?
My location obtaining scripts are in JavaScript file (googleMaps.js) which is my custom JavaScript code that obtains location and plots the marker for current location. Additionally, it will also plot multiple marker for nearby business location.
In addition, I Manually gave location permission in the Android emulator, even that did not help
Steps to Reproduce
The steps to create are long.
Version with bug
Preview 13 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
android
Did you find any workaround?
No
Relevant log output
In the picture
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (10 by maintainers)
Top Related StackOverflow Question
With the link you added earlier, I added this code to your
MauiProgram.csNot 100% sure if these are all needed, but at least this makes it work 😃
Additionally I noticed a Google Maps API key in there… You might want to invalidate that one now 😉
So i updated the repo to check if native GPS/Location would work and it does. so now in the repo i have native code that is working, but at the same time JavaScript/webview which is not working.
I would have ended up using native code and forget about obtaining location from JavaScript for Location, but native code does not have live tracking, i would have to get it via timer. I also noticed that getting location via native code is extremely slow as well.
As suggested by @Eilon there might be permission that need to be enabled for WebView/BlazorWebView since that is browser-based permission.
Now when I use the same code in Blazor wasm project, i don’t need to specify the permission upfront, when JavaScript Code (that will get gps coordinate) is about to execute it prompts user for permission. So, wondering if it is allowed to provide those permission upfront in the code, like we do in native code.