是否可以从 WinJS 中的 Windows Phone 8.1 应用程序调用 GPS 设置?

Is possible to call the GPS settings from a Windows Phone 8.1 App in WinJS?

我在 WinJS 中有一个 Windows Phone 8.1 应用程序需要 GPS。 我希望如果 GPS 关闭,应用程序会将用户重定向到 phone 的 gps 设置,这样他就可以轻松打开它。 可能吗?

也许使用 "Windows.System.Launcher"

您可以这样尝试:

// Create a Uri object from a URI string 
                    var uri = new Windows.Foundation.Uri("ms-settings:privacy-location");
                    Windows.System.Launcher.launchUriAsync(uri).then(
                   function (success) {
                   if (success) {
                           // URI launched
                       } else {
                           // URI launch failed
                       }
                   });

我写了一个关于如何获取位置的示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WebApp</title>

<!-- WinJS references -->
<link href="WinJS/css/ui-dark.css" rel="stylesheet" />
<script src="WinJS/js/base.js"></script>
<script src="WinJS/js/ui.js"></script>

<!-- WebApp references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>

<script type="text/javascript">
        function setText(val, e) {
            document.getElementById(e).value = val;
        }
        function insertText(val, e) {
            document.getElementById(e).value += val;
        }
        var nav = null;
        function requestPosition() {
          if (nav == null) {
              nav = window.navigator;
          }
          if (nav != null) {
              var geoloc = nav.geolocation;
              if (geoloc != null) {
                  geoloc.getCurrentPosition(successCallback, errorCallback);
              }
              else {
                  console.log("Geolocation not supported");
              }
          }
          else {
              console.log("Navigator not found");
          }
        }
        function successCallback(position)
        {
           setText(position.coords.latitude, "latitude");
           setText(position.coords.longitude, "longitude");
        }

        function errorCallback(error) {
            var message = "";
            // Check for known errors
            switch (error.code) {
                case error.PERMISSION_DENIED:
                    message = "This website does not have permission to use " +
                              "the Geolocation API";
                    break;
                case error.POSITION_UNAVAILABLE:
                    message = "The current position could not be determined.";
                    break;
                case error.PERMISSION_DENIED_TIMEOUT:
                    message = "The current position could not be determined " +
                              "within the specified timeout period.";
                    break;
            }
            // If it's an unknown error, build a message that includes
            // information that helps identify the situation, so that
            // the error handler can be updated.
            if (message == "")
            {
                var strErrorCode = error.code.toString();
                message = "The position could not be determined due to " +
                          "an unknown error (Code: " + strErrorCode + ").";
            }
            console.log(message);
}
</script>
<style></style>
</head>
<body>

<label for="latitude">Latitude: </label><input id="latitude" /> <br />
<label for="longitude">Longitude: </label><input id="longitude" /> <br />
<input type="button" onclick="requestPosition()" value="Get Latitude and Longitude" />



</body>

</html>

这是document关于这个