繁体   English   中英

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

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

我在WinJS中有一个需要GPS的Windows Phone 8.1应用程序。 我希望如果GPS关闭,应用程序会将用户重定向到手机的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>

这是关于此的文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM