如何在不始终加载整个地图的情况下刷新图标位置?

时间:2018-12-18 17:46:05

标签: javascript google-maps google-api google-api-java-client

我参考下面的Google地图示例。 我正在尝试每10秒刷新一组新的经纬度来刷新图标位置,因此每隔10秒我将传递新的经度/纬度,以便图标移动(例如移动的汽车) var uluru {lat:51.89269433333334,lng:-0.47702666666666665};

我的问题是: 如果不每10秒加载一次地图,是否可以每10秒更新背景的经纬度?还是我们必须每10秒刷新一次地图? 如果是的话,请让我知道。

感谢您的帮助

  <!DOCTYPE html>
    <html>
      <head>
        <style>
           /* Set the size of the div element that contains the map */
          #map {
            height: 800px;  /* The height is 400 pixels */
            width: 100%;  /* The width is the width of the web page */
           }
        </style>
      </head>
      <body>
        <h3>My Google Maps Demo</h3>
        <!--The div element for the map -->
        <div id="map"></div>
        <script>
    // Initialize and add the map
    function initMap() {
      // The location of Uluru
      var uluru = {lat: 51.89269433333334, lng: -0.47702666666666665};
      // The map, centered at Uluru
      var map = new google.maps.Map(
          document.getElementById('map'), {zoom: 13, center: uluru});
      // The marker, positioned at Uluru
      var marker = new google.maps.Marker({position: uluru, map: map});
    }
        </script>
        <!--Load the API from the specified URL
        * The async attribute allows the browser to render the page while the API loads
        * The key parameter will contain your own API key (which is not needed for this tutorial)
        * The callback parameter executes the initMap() function
        -->
        <script async defer
        src="https://maps.googleapis.com/maps/api/js?key=&callback&callback=initMap">
        </script>
      </body>
    </html>

1 个答案:

答案 0 :(得分:0)