html5地理操作在chrome/windows7中不起作用.但它在chrome/XP中工作..html5有什么问题吗



我正在创建只能在chrome中工作的混合应用程序。在我的应用程序中,我使用HTML5地理位置。。这在chrome/XP中运行良好,但在chrome/windows 7中不起作用。。。在执行下面的功能时,它请求我允许使用当前位置。我点击了"允许",但之后没有回应。我找不到真正的问题。请帮帮我。。

 if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(self.showPosition);
function showPosition(position)
{
        var currentLatitude = position.coords.latitude;
        var currentLongitude = position.coords.longitude;                           
        localStorage.DeviceLocation=currentLatitude+","+currentLongitude;                                                   
        $("#curr_loc_target").html("<b>Current location enabled as target </b> <BR> <b>Latitude :</b> "+currentLatitude.toFixed(5)+" <b>Longitude : </b>"+currentLongitude.toFixed(5));
       $("#curr_loc_target").show();                                    

   }
}

这应该会给出您正在查找的错误。它在我的chrome win 7上不起作用,错误是在本地运行时拒绝用户权限,但上传到服务器时不允许。可能会尝试将其加载到服务器上,而不是使用文件:///协议运行。应该做这个把戏。Chrome在本地运行时对其允许的内容感到讨厌。

$(document).ready(function(){
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition, showError);
    function showPosition(position) {
            var currentLatitude = position.coords.latitude;
            var currentLongitude = position.coords.longitude;                           
            alert(currentLongitude);
            localStorage.DeviceLocation=currentLatitude+","+currentLongitude;                                                   
            $("#curr_loc_target").html("<b>Current location enabled as target </b> <BR> <b>Latitude :</b> "+currentLatitude.toFixed(5)+" <b>Longitude : </b>"+currentLongitude.toFixed(5));
           $("#curr_loc_target").show();                                    
        }   
    } else {
        alert("geoloc not working");
    }   
    function showError(error) {
      var x = $('#curr_loc_target');
      switch(error.code) {
        case error.PERMISSION_DENIED:
          x.html("User denied the request for Geolocation.");
          break;
        case error.POSITION_UNAVAILABLE:
          x.html("Location information is unavailable.");
          break;
        case error.TIMEOUT:
          x.html("The request to get user location timed out.");
          break;
        case error.UNKNOWN_ERROR:
          x.html("An unknown error occurred.");
          break;
        }
    }
});

最新更新