如何在不一直加载完整地图的情况下刷新图标位置?
how to refresh an Icon position without loading the full map all the time?
我参考下面的 Google 地图示例。
我正在尝试每 10 秒用新的一组经纬度刷新图标位置,因此每 10 秒我将传递新的 lat/lon 以便图标移动(如移动的汽车)
var uluru {lat: 51.89269433333334, lng: -0.47702666666666665};
我的问题是:
如果不每 10 秒加载一次地图,我们可以每 10 秒更新一次图标的 lat/lon 背景吗?还是我们必须每 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>
我参考下面的 Google 地图示例。 我正在尝试每 10 秒用新的一组经纬度刷新图标位置,因此每 10 秒我将传递新的 lat/lon 以便图标移动(如移动的汽车) var uluru {lat: 51.89269433333334, lng: -0.47702666666666665};
我的问题是: 如果不每 10 秒加载一次地图,我们可以每 10 秒更新一次图标的 lat/lon 背景吗?还是我们必须每 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>