1. <tfoot id='Mf5DO'></tfoot>

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

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

        删除先前的标记并在更新的 lat lng 中添加标记

        Remove the previous marker and add marker in the updated lat lng(删除先前的标记并在更新的 lat lng 中添加标记)
            <bdo id='f6Gwt'></bdo><ul id='f6Gwt'></ul>
          • <i id='f6Gwt'><tr id='f6Gwt'><dt id='f6Gwt'><q id='f6Gwt'><span id='f6Gwt'><b id='f6Gwt'><form id='f6Gwt'><ins id='f6Gwt'></ins><ul id='f6Gwt'></ul><sub id='f6Gwt'></sub></form><legend id='f6Gwt'></legend><bdo id='f6Gwt'><pre id='f6Gwt'><center id='f6Gwt'></center></pre></bdo></b><th id='f6Gwt'></th></span></q></dt></tr></i><div id='f6Gwt'><tfoot id='f6Gwt'></tfoot><dl id='f6Gwt'><fieldset id='f6Gwt'></fieldset></dl></div>

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

            <small id='f6Gwt'></small><noframes id='f6Gwt'>

                  <tfoot id='f6Gwt'></tfoot>
                    <tbody id='f6Gwt'></tbody>
                  本文介绍了删除先前的标记并在更新的 lat lng 中添加标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 GPS 设备,它每 10 秒发送一次数据.我将数据(lat、lng)保存在 MySql 数据库中.我正在从数据库中检索数据并使用 xmlHttpRequest() 将标记放在这些 lat lng 上.我还在 10 秒内使用 setInterval() 到 xmlHttpRequest.标记被很好地添加,但在刷新整个站点后添加新标记,而不是在 xmlhttpreq 上 10 秒后添加.

                  I have a gps device which sends data every 10 seconds. I am saving the data (lat, lng) in the MySql database., I am retrieving the data from the DB and putting the markers on those lat lng using xmlHttpRequest(). I am also using setInterval() to xmlHttpRequest on 10 seconds. The markers are being added finely but new markers are added after refresh the whol site, not after 10 seconds on xmlhttpreq.

                  我还有两个问题 -

                  1. 我的 xmlHttpRequest() 在 10 秒后刷新正常,并从 Network、XHR 看到 get_data.php 文件,但它没有在地图上添加新标记,但 10 秒后请求 xmlHttp.我怎样才能更新标记?

                  1. My xmlHttpRequest() is refreshing fine after 10 seconds and getting the get_data.php file as i am seeing from Network,XHR but it is not adding new marker on the map, but the xmlHttp is requested after 10 seconds. How can i also update the marker?

                  正在根据数据库数据添加标记,但我不想要很多标记,我只想要一个每 10 秒更新一次位置的标记.所以之前的标记将被删除,新的标记将被添加.我怎样才能做到这一点?下面是我的代码 -

                  Markers are being added according to the DB data but i do not want many markers, i just want one marker which will be updated position every 10 seconds. So the previous marker will be deleted and the new marker will be added. How can i do that? Below is my code -

                  index.html

                  <!DOCTYPE HTML>
                  <html>
                      <head>
                          <style type="text/css">
                  
                  
                  
                  
                  #map-canvas{
                              height: 500px;
                          }
                      </style>
                      <title> Google Map Test</title>
                  
                      <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
                  
                      <script type="text/javascript">
                          var map;
                          //var geocoder = new google.maps.Geocoder();
                          //var infowindow = new google.maps.InfoWindow();
                  
                  
                  function makeRequest(url, callback) {
                      var request;
                      if (window.XMLHttpRequest) {
                          request = new XMLHttpRequest(); // IE7+, Firefox, Chrome, Opera, Safari
                      } else {
                          request = new ActiveXObject("Microsoft.XMLHTTP"); // IE6, IE5
                      }
                      request.onreadystatechange = function() {
                          console.log(request)
                      if (request.readyState == 4 && request.status == 200) {
                          callback(request);
                      }
                  }
                      request.open("GET", url, true);
                  request.send();
                  console.log(request)
                                }
                  
                          function initialise(){
                              var mapOptions = {
                                  center: new google.maps.LatLng(23.7000, 90.3667),
                                  zoom: 8,
                                  mapTypeId: google.maps.MapTypeId.ROADMAP
                              };
                              map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);    
                  
                      makeRequest('get_data.php', function(data) {
                      var data = JSON.parse(data.responseText);
                  
                      for (var i = 0; i < data.length; i++) {
                          displayLocation(data[i]);
                      }
                           });
                      // var myLatLng = {lat: 23.7000, lng: 90.3667};
                      //  var marker = new google.maps.Marker({
                      //     map: map, 
                      //     position: myLatLng,
                      //     title: 'test!'
                      // });
                  
                          }
                          setInterval("makeRequest('get_data.php')",10000);
                  
                      function displayLocation(location) {
                  
                  //var content =   '<div class="infoWindow"><strong>'  + location.lat        +'</strong>'
                    //              + '<br/>'     + location.lon + '</div>';
                  
                  console.log(location.lat)
                  // location = JSON.parse(location)
                      var position = new google.maps.LatLng(parseFloat(location.lat), parseFloat(location.lng));
                      var marker = new google.maps.Marker({
                          map: map, 
                          position: position,
                          title: 'test!'
                      });
                  
                  
                  
                      // google.maps.event.addListener(marker, 'click', function() {
                      //     infoWindow.setContent(content);
                      //     infoWindow.open(map,marker);
                      // });
                  }
                  
                  
                          </script>
                  
                  
                      </head>
                      <body>
                          <div id="map-canvas"></div>
                  
                          <script type="text/javascript">
                  initialise();
                          </script>
                  
                      </body>
                  </html> 
                  

                  get_data.php

                  get_data.php

                      $connection = mysqli_connect("localhost", "root", "123", "gpsdata") or die("Error " . mysqli_error($connection));
                      $sql = "select * from locations";
                      $result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
                      $emparray = [];
                  
                      while($row = mysqli_fetch_assoc($result)) {
                          $emparray[] = $row;
                      }
                  
                      echo json_encode($emparray);
                  
                      mysqli_close($connection);
                  

                  推荐答案

                  您有两个选择,都涉及在 displayLocation 函数之外保留对标记的引用:

                  You have two options, both involve keeping a reference to the marker outside of the displayLocation function:

                  1. 使用引用移动现有标记

                  var marker;
                  function displayLocation(location) {
                    console.log(location.lat)
                      var position = new google.maps.LatLng(parseFloat(location.lat), parseFloat(location.lng));
                      if (marker && marker.setPosition) {
                        // if the marker already exists, move it (set its position)
                        marker.setPosition(location);
                      } else {
                        // create a new marker, keeping a reference
                        marker = new google.maps.Marker({
                          map: map, 
                          position: position,
                          title: 'test!'
                        });
                      }
                  }
                  

                  1. 从地图中移除现有标记并创建一个新标记

                  var marker;
                  function displayLocation(location) {
                    console.log(location.lat)
                      var position = new google.maps.LatLng(parseFloat(location.lat), parseFloat(location.lng));
                      if (marker && marker.setMap) {
                        // if the marker already exists, remove it from the map
                        marker.setMap(null);
                      }
                      // create a new marker, keeping a reference
                      marker = new google.maps.Marker({
                        map: map, 
                        position: position,
                        title: 'test!'
                      });
                  }
                  

                  这篇关于删除先前的标记并在更新的 lat lng 中添加标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  When should use doctrine ORM and when zend-db-table?(什么时候应该使用学说 ORM,什么时候应该使用 zend-db-table?)
                  Doctrine - self-referencing entity - disable fetching of children(Doctrine - 自引用实体 - 禁用获取子项)
                  Doctrine 2, query inside entities(原则 2,实体内部查询)
                  Complex WHERE clauses using the PHP Doctrine ORM(使用 PHP Doctrine ORM 的复杂 WHERE 子句)
                  Doctrine - OneToMany relation, all result row doesn#39;t fetch in object(Doctrine - OneToMany 关系,所有结果行不获取对象)
                  Doctrine and unrefreshed relationships(教义和未更新的关系)
                    <tbody id='sHslt'></tbody>

                    <small id='sHslt'></small><noframes id='sHslt'>

                      <bdo id='sHslt'></bdo><ul id='sHslt'></ul>

                      • <legend id='sHslt'><style id='sHslt'><dir id='sHslt'><q id='sHslt'></q></dir></style></legend>

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