<tfoot id='73emv'></tfoot>

      <small id='73emv'></small><noframes id='73emv'>

      • <bdo id='73emv'></bdo><ul id='73emv'></ul>
      1. <legend id='73emv'><style id='73emv'><dir id='73emv'><q id='73emv'></q></dir></style></legend>

        <i id='73emv'><tr id='73emv'><dt id='73emv'><q id='73emv'><span id='73emv'><b id='73emv'><form id='73emv'><ins id='73emv'></ins><ul id='73emv'></ul><sub id='73emv'></sub></form><legend id='73emv'></legend><bdo id='73emv'><pre id='73emv'><center id='73emv'></center></pre></bdo></b><th id='73emv'></th></span></q></dt></tr></i><div id='73emv'><tfoot id='73emv'></tfoot><dl id='73emv'><fieldset id='73emv'></fieldset></dl></div>

        没有 SSL 连接的地理位置

        时间:2023-09-06
        • <small id='Sz3Pm'></small><noframes id='Sz3Pm'>

        • <tfoot id='Sz3Pm'></tfoot>
          • <bdo id='Sz3Pm'></bdo><ul id='Sz3Pm'></ul>
                <tbody id='Sz3Pm'></tbody>

                <legend id='Sz3Pm'><style id='Sz3Pm'><dir id='Sz3Pm'><q id='Sz3Pm'></q></dir></style></legend>
                <i id='Sz3Pm'><tr id='Sz3Pm'><dt id='Sz3Pm'><q id='Sz3Pm'><span id='Sz3Pm'><b id='Sz3Pm'><form id='Sz3Pm'><ins id='Sz3Pm'></ins><ul id='Sz3Pm'></ul><sub id='Sz3Pm'></sub></form><legend id='Sz3Pm'></legend><bdo id='Sz3Pm'><pre id='Sz3Pm'><center id='Sz3Pm'></center></pre></bdo></b><th id='Sz3Pm'></th></span></q></dt></tr></i><div id='Sz3Pm'><tfoot id='Sz3Pm'></tfoot><dl id='Sz3Pm'><fieldset id='Sz3Pm'></fieldset></dl></div>

                  本文介绍了没有 SSL 连接的地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在开发一个使用地理位置坐标的应用程序.我使用 HTML5 地理定位功能来找出网站访问者的位置,但问题在于 Chrome 不支持不安全来源的 GeoLocation.

                  I am developing an application which uses geolocation coordinates. I used the HTML5 geolocation feature to find out the location of the site visitor, but the issue is with Chrome which doesnt support GeoLocation on insecure origins.

                    function showPosition(){
                      if(navigator.geolocation){
                          navigator.geolocation.getCurrentPosition(function(position){
                              var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")";
                              document.getElementById("result").innerHTML = positionInfo;
                          });
                      } else{
                          alert("Sorry, your browser does not support HTML5 geolocation.");
                      }
                  }
                  

                  这里的代码 getCurrentPosition 无法使用,因为我的网站没有连接 SSL.

                  Here is the code getCurrentPosition is not working in as my site is not SSL connected .

                  Chrome 警告: getCurrentPosition() 和 watchPosition() 不再适用于不安全的来源.要使用此功能,您应该考虑将您的应用程序切换到安全来源,例如 HTTPS.

                  Warning by Chrome : getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS.

                  还有其他方法可以在 chrome 上获取坐标/LatLong 值吗?[仅在不安全的连接上]

                  Is there any other way to get coordinates/LatLong values on chrome ? [on Insecure connection only]

                  EDIT :它在我的机器上使用 localhost:80 工作,但在 http 上的测试 url 中不工作

                  EDIT : It is working in my machine using localhost:80 but not working in test url which is on http

                  推荐答案

                  var apiGeolocationSuccess = function(position) {
                      alert("API geolocation success!
                  
                  lat = " + position.coords.latitude + "
                  lng = " + position.coords.longitude);
                  };
                  
                  var tryAPIGeolocation = function() {
                      jQuery.post( "https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyDCa1LUe1vOczX1hO_iGYgyo8p_jYuGOPU", function(success) {
                          apiGeolocationSuccess({coords: {latitude: success.location.lat, longitude: success.location.lng}});
                    })
                    .fail(function(err) {
                      alert("API Geolocation error! 
                  
                  "+err);
                    });
                  };
                  
                  var browserGeolocationSuccess = function(position) {
                      alert("Browser geolocation success!
                  
                  lat = " + position.coords.latitude + "
                  lng = " + position.coords.longitude);
                  };
                  
                  var browserGeolocationFail = function(error) {
                    switch (error.code) {
                      case error.TIMEOUT:
                        alert("Browser geolocation error !
                  
                  Timeout.");
                        break;
                      case error.PERMISSION_DENIED:
                        if(error.message.indexOf("Only secure origins are allowed") == 0) {
                          tryAPIGeolocation();
                        }
                        break;
                      case error.POSITION_UNAVAILABLE:
                        alert("Browser geolocation error !
                  
                  Position unavailable.");
                        break;
                    }
                  };
                  
                  var tryGeolocation = function() {
                    if (navigator.geolocation) {
                      navigator.geolocation.getCurrentPosition(
                          browserGeolocationSuccess,
                        browserGeolocationFail,
                        {maximumAge: 50000, timeout: 20000, enableHighAccuracy: true});
                    }
                  };
                  
                  tryGeolocation();
                  

                  这篇关于没有 SSL 连接的地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:HTML5 的 GeoLocation 究竟是如何工作的? 下一篇:存储 HTML5 地理位置数据

                  相关文章

                  最新文章

                      <tfoot id='1NtrM'></tfoot>
                      <legend id='1NtrM'><style id='1NtrM'><dir id='1NtrM'><q id='1NtrM'></q></dir></style></legend>
                    1. <small id='1NtrM'></small><noframes id='1NtrM'>

                      <i id='1NtrM'><tr id='1NtrM'><dt id='1NtrM'><q id='1NtrM'><span id='1NtrM'><b id='1NtrM'><form id='1NtrM'><ins id='1NtrM'></ins><ul id='1NtrM'></ul><sub id='1NtrM'></sub></form><legend id='1NtrM'></legend><bdo id='1NtrM'><pre id='1NtrM'><center id='1NtrM'></center></pre></bdo></b><th id='1NtrM'></th></span></q></dt></tr></i><div id='1NtrM'><tfoot id='1NtrM'></tfoot><dl id='1NtrM'><fieldset id='1NtrM'></fieldset></dl></div>

                      • <bdo id='1NtrM'></bdo><ul id='1NtrM'></ul>