我試圖在一個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