小编Oll*_*lie的帖子

Xamarin Forms WebView 地理位置问题

我正在尝试在 xamarin 表单应用程序中启用 webview 以获取 android 设备的当前 GPS 坐标。当前,当在手机或笔记本电脑上的 chrome 浏览器中打开时,webview/网站将返回 GPS 坐标,但在应用程序中不会。试图让这个工作尽可能简单,并在之后扩展它。

到目前为止的代码: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>
Run Code Online (Sandbox Code Playgroud)

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) …
Run Code Online (Sandbox Code Playgroud)

android webview xamarin xamarin.forms

3
推荐指数
1
解决办法
2858
查看次数

标签 统计

android ×1

webview ×1

xamarin ×1

xamarin.forms ×1