我试图在一个xamarin表单应用程序中启用webview以获取android设备的当前GPS坐标。目前webview /网站将在手机或笔记本电脑上的chrome浏览器中打开时返回GPS坐标,但在应用程序中不会。试图尽可能简化工作并在之后进行扩展。Xamarin Forms WebView地理定位问题
到目前为止的代码: XAML页面:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="UITrial.Page2"
BackgroundColor = "#f0f0ea">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<WebView Source="https://danu6.it.nuigalway.ie/OliverInternetProgramming/project/Loginproject.html" />
</ContentPage>
HTML页面:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";}
}
function showPosition(position) {
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>
您是否配置了您的应用程序以允许使用GPS? – SergioAMG
是的,已经在Android清单中配置了许可,以允许优良和粗略的位置 – Ollie