开发者

jquery mobile geolocation

simple question.. how do I set a redirect if the user selects not allow for the geolocator pop up? If allow and error I have covered. works fine. But I' not sure how to set the not allow selection.

function showLocation(position) {
      var latitude = position.coords.latitude;
      var longitude = position.coords.longitude;
      //window.location = "/restaurant/latitude/40.714269/longitude/-74.005972/";
      window.location = "/restaura开发者_如何转开发nt/";
    }

    function errorHandler(err) {
      if(err.code == 1) {
            alert("Error: Can not access!");
      }else if( err.code == 2) {
            alert("Error: Position is unavailable!");
      }
    }
    function getLocation(){

       if(navigator.geolocation){
          // timeout at 60000 milliseconds (60 seconds)
          var options = {timeout:60000};
          navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
       }else{
          alert("Sorry, browser does not support geolocation!");
       }
    }


According to the W3C Geolocation API spec, the error handler should be invoked with the appropriate reason for the failure. This includes permission denied by the user.

Unfortunately, it seems like there is a bug/feature in Firefox where if you select Not Now from the popup, nothing happens - the error handler is not called. However, if you select Never Share, your error handler does get called and with the code you posted, you'll see the alert saying Error: Can not access!.

There is no third option in Chrome (only Allow and Deny) and things seem to work just fine there.

Also see How to detect negative user response for geolocation where a solution is proposed (it involves using a timeout to detect that nothing has happened and treating it the same as permission denied)


I see that you have tried setting the window.location. Why does that not work for you?

window.location = "../nonGeoLocationPage.html"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜