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

          <bdo id='nXccu'></bdo><ul id='nXccu'></ul>
        <legend id='nXccu'><style id='nXccu'><dir id='nXccu'><q id='nXccu'></q></dir></style></legend>
      1. <small id='nXccu'></small><noframes id='nXccu'>

      2. <tfoot id='nXccu'></tfoot>
      3. 高精度地理定位Html5

        时间:2023-09-06
        <tfoot id='GsCJt'></tfoot>

          <tbody id='GsCJt'></tbody>
        1. <small id='GsCJt'></small><noframes id='GsCJt'>

          <legend id='GsCJt'><style id='GsCJt'><dir id='GsCJt'><q id='GsCJt'></q></dir></style></legend>

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

                <bdo id='GsCJt'></bdo><ul id='GsCJt'></ul>
                  本文介绍了高精度地理定位Html5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用嵌入式 GPS 定位设备(例如应用程序共享位置).我读过 enableHighAccuracy: true 是可能的.

                  I am tring to locate a device using the embedded GPS (like whats app share location). I've read that it is possible with enableHighAccuracy: true.

                  如何在此代码中设置 enableHighAccuracy: true?我尝试了不同的位置,但它不起作用.

                  How can I set enableHighAccuracy: true in this code? I tried in different positions but it doesn't work.

                  <script type="text/javascript">
                      if (navigator.geolocation) {
                          navigator.geolocation.getCurrentPosition(function(position) {
                              var latitude = position.coords.latitude;
                              var longitude = position.coords.longitude;
                              var accuracy = position.coords.accuracy;
                              var coords = new google.maps.LatLng(latitude, longitude);
                              var mapOptions = {
                                  zoom: 15,
                                  center: coords,
                                  mapTypeControl: true,
                                  navigationControlOptions: {
                                      style: google.maps.NavigationControlStyle.SMALL
                                  },
                                  mapTypeId: google.maps.MapTypeId.ROADMAP
                              };
                  
                              var capa = document.getElementById("capa");
                              capa.innerHTML = "latitude: " + latitude + ", longitude: " + ", accuracy: " + accuracy;  
                  
                              map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);
                              var marker = new google.maps.Marker({
                                  position: coords,
                                  map: map,
                                  title: "ok"
                              });
                          });
                  
                      } else {
                          alert("Geolocation API is not supported in your browser.");
                      }
                  
                  </script>
                  

                  推荐答案

                  您需要一个 PositionOptions 对象,您可以在其中按照 API 设置高精度标志.

                  You need a PositionOptions object, in which you set the high accuracy flag following the API.

                  我从这里引用:http://diveintohtml5.info/geolocation.html

                  getCurrentPosition() 函数有一个可选的第三个参数,a位置选项对象.您可以在其中设置三个属性位置选项对象.所有属性都是可选的.你可以设置任何或全部或没有.

                  The getCurrentPosition() function has an optional third argument, a PositionOptions object. There are three properties you can set in a PositionOptions object. All the properties are optional. You can set any or all or none of them.

                  POSITIONOPTIONS OBJECT
                  
                  Property            Type        Default         Notes
                  --------------------------------------------------------------
                  enableHighAccuracy  Boolean     false           true might be slower
                  timeout             long        (no default)    in milliseconds
                  maximumAge          long        0               in milliseconds
                  

                  所以,它应该像这样工作:

                  So, it should work like this:

                  if (navigator.geolocation) {
                      navigator.geolocation.getCurrentPosition(function(position) {
                          var latitude = position.coords.latitude;
                          var longitude = position.coords.longitude;
                          var accuracy = position.coords.accuracy;
                          var coords = new google.maps.LatLng(latitude, longitude);
                          var mapOptions = {
                              zoom: 15,
                              center: coords,
                              mapTypeControl: true,
                              navigationControlOptions: {
                                  style: google.maps.NavigationControlStyle.SMALL
                              },
                              mapTypeId: google.maps.MapTypeId.ROADMAP
                          };
                  
                          var capa = document.getElementById("capa");
                          capa.innerHTML = "latitude: " + latitude + ", longitude: " + ", accuracy: " + accuracy;
                  
                          map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);
                          var marker = new google.maps.Marker({
                              position: coords,
                              map: map,
                              title: "ok"
                          });
                  
                      },
                      function error(msg) {alert('Please enable your GPS position feature.');},
                      {maximumAge:10000, timeout:5000, enableHighAccuracy: true});
                  } else {
                      alert("Geolocation API is not supported in your browser.");
                  }
                  

                  注意到我在 getCurrentPosition 调用中添加了以下 2 个参数:

                  Noticed I added the following 2 parameters to getCurrentPosition call:

                  1. 函数错误(msg){alert('请在未来启用您的GPS定位.');}

                  当无法获取 GPS 或触发超时时调用此函数.

                  This function is called when GPS could not be retrieved or the timeout has been triggered.

                  {maximumAge:10000, timeout:5000, enableHighAccuracy: true});

                  这些是选项.我们不想要超过 10 秒 (maximumAge:10000) 的 gps 数据.我们不想等待超过 5 秒的响应 (timeout:5000),我们希望启用高精度 (enableHighAccuracy: true).

                  These are the options. We don't want gps data that is older than 10 seconds (maximumAge:10000). We don't want to wait longer than 5 seconds for a response (timeout:5000) and we want to enable high accuracy (enableHighAccuracy: true).

                  另请参阅:Geolocation HTML5 enableHighAccuracy True 、 False 还是 Best Option?

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

                  上一篇:HTML5 地理位置如何工作? 下一篇:Safari 5 中的地理位置

                  相关文章

                  最新文章

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

                    2. <small id='SP3Hh'></small><noframes id='SP3Hh'>