【发布时间】:2017-10-01 19:39:57
【问题描述】:
为什么我的任何浏览器都不支持地理定位? 我是 javascript 世界的新手。
这是我在节点 js 服务器上运行的代码。
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
</head>
<body>
<button onclick="getLocation()">Get coords</button>
<h1 id="coords"></h1>
<script>
var x=document.getElementById('coords');
function getLocation(){
if (navigator.Geolocation) {
navigator.Geolocation.getCurrentPosition(showPosition);
}
else{
x.innerHTML="Geolocation is not supported";
}
function showPosition(position){
console.log(position.coords.latitude);
}
}
</script>
</body>
</html>
【问题讨论】:
标签: javascript node.js html mean-stack