[英]I want to recieve geo location using webview of site but in flutter dart app using javascript
JavaScript Code: JavaScript 代码:
var x = document.getElementById("x");
document.getElementById('button').onclick = function()
{
function showPosition(position)
{
console.log("in showPosition");
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
alert("button was clicked");
console.log("sdfghj");
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
console.log("in if ");
}else
{
x.innerHTML = "Geolocation is not supported by this browser.";
console.log("in else ");
}
}
But the permission request popup never opens.但是权限请求弹出窗口永远不会打开。 Flutter Code:
颤振代码:
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebViewStack extends StatefulWidget {
const WebViewStack({Key? key}) : super(key: key);
@override
State<WebViewStack> createState() => _WebViewStackState();
}
void main() {
runApp(
const MaterialApp(
home: WebViewStack(),
),
);
}
class _WebViewStackState extends State<WebViewStack> {
var loadingPercentage = 0;
@override
Widget build(BuildContext context) {
return Stack(
children: [
WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: 'example.com',
),
],
);
}
}
I am working on a project that needs to get user's current location using HTML 5 geolocation.我正在开发一个需要使用 HTML 5 地理位置获取用户当前位置的项目。 But I need to know why WebView is not showing my current location.
但我需要知道为什么 WebView 没有显示我当前的位置。 What I've to do to show the map and current location in WebView??
我需要做什么才能在 WebView 中显示地图和当前位置?
If your question is about missing permissions, you should use a plugin like Permission Handler - https://pub.dev/packages/permission_handler Read through the Readme and you are done.如果您的问题是关于缺少权限,您应该使用像Permission Handler这样的插件 - https://pub.dev/packages/permission_handler通读自述文件,您就完成了。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.