0
我在線學習本教程,教您如何使用HTML5的新內置功能和谷歌地圖API獲取您當前的位置(地理定位)。navigator.Geolocation GetCurrentpositon不適用於Chrome和Firefox
˚<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Navigator</title>
</head>
<script src="js/jquery.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script>
x = navigator.geolocation;
x.getCurrentPosition(success, failure);
function success(position) {
var mylat = position.coords.latitude;
var mylong = position.coords.longitude;
$('#lat').htm(mylat);
$('#long').html(mylong);
}
function failure() {
$('#lat').html("<h3> No co-ordinates available!</h3>");
}
</script>
<body>
<!--map placeholder -->
<div id="map">
</div>
<div id="lat"></div>
<div id="long"></div>
</body>
</html>
我試着在谷歌和Firefox上運行這段代碼。 Google阻止我看到我目前的位置。我收到失敗消息「沒有座標可用!」 至於Firefox,它的作品非常棒!
Chrome在這裏有什麼問題?一位朋友建議我應該嘗試使用我的IP地址獲取我的位置。該怎麼辦?有沒有辦法阻止我的當前位置?
你有一個錯字'$( '#LAT')HTM(mylat);'=>'$(」 #lat').html(mylat);' – Mathias
這個在Chrome中可以工作33 http://jsfiddle.net/borglinm/LVBVy/ – Mathias
我要做的第一件事就是檢查你的chrome設置中是否有位置設置(在隱私 - >內容設置下找到)設置爲允許或要求跟蹤您的位置。也可以,您已經阻止過一次 - 在這種情況下,您可以從「管理例外」中刪除例外。 –