【问题标题】:how to refresh an Icon position without loading the full map all the time?如何在不一直加载完整地图的情况下刷新图标位置?
【发布时间】:2019-05-19 04:36:50
【问题描述】:

我参考下面的谷歌地图示例。 我正在尝试使用新的 lat、lng 设置每 10 秒刷新一次图标位置,因此每 10 秒我将通过新的 lat/lon 以便图标移动(如移动汽车) 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>

【问题讨论】:

  • 嗨@geocodezip,谢谢,我看到了那个,但它已经有4年了,我不确定在google recept api结构更改后,如果那个代码仍然有效,我在看另一个示例developers.google.com/maps/documentation/javascript/examples/… 在此示例中,我可以通过每次单击删除添加图标,但是我们可以创建动态数组而不是单击,而不是单击?例如,如果我们调用我们的脚本,每 10 秒获取 lat/on 并通过 addMarker 函数传递它,它会工作吗?

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


【解决方案1】:

我已经修改了这个脚本,看起来工作正常

https://developers.google.com/maps/documentation/javascript/examples/marker-remove

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-22
    • 2019-01-08
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    相关资源
    最近更新 更多