html5 geoloaction is not working in chrome/windows7 . But its working in chrome / XP ...Is there any issue with html5

StackOverflow https://stackoverflow.com/questions/18235433

Question

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


   }
}
Was it helpful?

Solution

This should give you the error you are looking for. It doesn't work on my chrome win 7 and the error is user permission denied when running locally, but not when uploaded to a server. Might try getting this onto a server instead of running with the file:/// protocol. Should do the trick. Chrome is pesky about what it allows when running locally.

$(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;
        }
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top