0

I am creating hybrid application which should only work in chrome .In my app am using HTML5 geolocation..this is working fine in chrome/XP but its not working in chrome/windows 7 ... While executin the below function it is requesting me to allow to use current location .I clicked "allow" but after that no respond. I could not find the actual issue.Please help me out..

 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();                                    


   }
}
4

1 回答 1

0

这应该会给你你正在寻找的错误。它在我的 chrome win 7 上不起作用,错误是在本地运行时用户权限被拒绝,但在上传到服务器时却没有。可能会尝试将它放到服务器上,而不是使用 file:/// 协议运行。应该做的伎俩。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;
        }
    }
});
于 2013-08-14T15:31:43.773 回答