如何在页面加载后刷新javascript

时间:2017-04-15 16:51:11

标签: javascript html google-maps refresh

我在谷歌地图上有指针,我想更新而不加载整个地图。指针可以放在单独的Javascript文件中,但是如何重新加载

  1. 不刷新整页
  2. 如何每30秒左右刷新一次JS ..
  3. <html>
    
    <head>
      <style>
        #map {
          height: 100%;
        }
        
        html,
        body {
          height: 100%;
          margin: 0;
          padding: 0;
        }
      </style>
    </head>
    
    <body>
      <div id='map'></div>
      <script>
        function initMap() {
          var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 10,
            center: {
              lat: ".$latitude.",
              lng: ".$longitude."
            }
          });
    
          setMarkers(map);
    
        }
    
    
        var beaches = [");
    
    
            echo("['".$name.
              "', ".$lat.
              ",".$long.
              "],");
    
    
            function setMarkers(map) {
    
              var image = {
                url: '1.png',
    
              };
    
              var shape = {
                coords: [1, 1, 1, 20, 18, 20, 18, 1],
                type: 'poly'
              };
              for (var i = 0; i < beaches.length; i++) {
                var beach = beaches[i];
                var marker = new google.maps.Marker({
                  position: {
                    lat: beach[1],
                    lng: beach[2]
                  },
                  map: map,
                  icon: image,
                  shape: shape,
                  title: beach[0],
                  zIndex: beach[3]
                });
              }
            }
      </script>
    
      <script async defer src='https://maps.googleapis.com/maps/api/js?key=AIzaSyBVQaENEYHY2g-mRhD6_tj1cSK8DhQoqHI&callback=initMap'>
      </script>
    
    </body>
    
    </html>

1 个答案:

答案 0 :(得分:0)

使用JS操作地图不会刷新页面。如果您需要与后端进行任何通信,则可以使用AJAX。

static T valueOf(String)

https://www.w3schools.com/js/js_timing.asp

希望这会有所帮助。 :)