【发布时间】:2020-07-12 07:01:04
【问题描述】:
我想获取某个位置的纬度和经度。我正在使用 ejs 文件。 我在 w3shools 上找到了这段代码。但我不知道如何将它包含在 ejs 文件中并将数据返回到服务器。在后端我使用 express。你能帮忙吗?提前谢谢。
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(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;
}
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
【问题讨论】:
-
当我在 ejs 文件中编写此代码时,我收到错误导航器未定义
-
@doublesharp 请帮忙
-
这能回答你的问题吗? Navigator undefined in ejs file express
标签: javascript node.js express geolocation ejs