小编LeC*_*ans的帖子

我可以使用 HTML5 定位工具在 Python 中获得准确的地理位置吗?

我想使用 Python 脚本获得准确的位置。我尝试过基于 IP 位置的不同服务,但根本不起作用(总是离我的实际位置很远)。

我注意到 HTML5 地理定位工具在 Firefox 和 Google Chrome 上相当准确,因此我决定使用 selenium 模块启动网络浏览器并从中获取我的位置。

虽然我面临两个问题:首先,我无法强制 Firefox 或 Chrome 允许本地网页上的位置服务。其次,我不知道如何获取获取坐标的 JavaScript 函数的结果。

这是我到目前为止所做的:

地理.html

<html>
    <head>
        <title>Test</title>
    <p id="demo"></p>
        <script type="text/javascript">

var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
        return navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        return "Geolocation is not supported by this browser.";
    }
}



function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
}
        </script>
    </head>
    <body>
        <p>The element below will receive content</p> …
Run Code Online (Sandbox Code Playgroud)

html python position geolocation

5
推荐指数
1
解决办法
4026
查看次数

标签 统计

geolocation ×1

html ×1

position ×1

python ×1