Javascript 对地图更新感到困惑吗
我对使用谷歌地图和复杂的javascript非常陌生。记住这一点,我正试图创建一个网络地图,其中包含来自美国地质调查局的提要。此提要每5分钟更新一次。我希望使用相同的提要(一个geojson文件)每5分钟刷新一次地图 我的最终目标是在我的地图上显示/更新此提要和至少一个其他提要。在过去的四天里,我浏览了几十篇帖子,现在正处于超载和困惑的境地。有人能帮我清除雾气吗 我发布的代码99%都不是我的代码,大部分我都添加了注释,以便了解代码中发生了什么Javascript 对地图更新感到困惑吗,javascript,html,json,google-maps,Javascript,Html,Json,Google Maps,我对使用谷歌地图和复杂的javascript非常陌生。记住这一点,我正试图创建一个网络地图,其中包含来自美国地质调查局的提要。此提要每5分钟更新一次。我希望使用相同的提要(一个geojson文件)每5分钟刷新一次地图 我的最终目标是在我的地图上显示/更新此提要和至少一个其他提要。在过去的四天里,我浏览了几十篇帖子,现在正处于超载和困惑的境地。有人能帮我清除雾气吗 我发布的代码99%都不是我的代码,大部分我都添加了注释,以便了解代码中发生了什么 <HTML> <HEAD>
<HTML>
<HEAD>
<TITLE>TEST OF MAP</TITLE>
<STYLE>
/* --------------------------------------------------- */
/* Set the map height explicitly to define the size of */
/* the DIV * element that contains the map. */
/* ----------------------------------------------------*/
#map {
height: 75%;
border: 5px solid green;
}
</STYLE>
</HEAD>
<SCRIPT type="text/javascript">
// --------------------------------------
// Set a refresh interval in milliseconds
// --------------------------------------
setInterval(page_refresh, 1*60000);
google.maps.event.addDomListener(window, 'load', initialize);
</SCRIPT>
<BODY>
<H1><CENTER>MAP Demo</CENTER></H1>
<DIV id="map"></DIV>
<SCRIPT>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: new google.maps.LatLng(35.4437,139.6380),
mapTypeId: 'terrain'
});
// ---------------------------------------------------------
// Create a <SCRIPT> tag and set the USGS URL as the source.
// ---------------------------------------------------------
var script = document.createElement('script');
// -----------------------------------------------------------------------
// Using a local copy of the GeoJSON stored on the USGS server
//
http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_hour.geojsonp
// -----------------------------------------------------------------------
script.src =
'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_hour.geojson
p';
document.getElementsByTagName('head')[0].appendChild(script);
}
// ------------------------------------------------------------------
// Loop through the results array and place a marker for each set of
// coordinates.
// ------------------------------------------------------------------
window.eqfeed_callback = function(results) {
for (var i = 0; i < results.features.length; i++) {
var coords = results.features[i].geometry.coordinates;
var latLng = new google.maps.LatLng(coords[1],coords[0]);
var marker = new google.maps.Marker({
position: latLng,
map: map
});
}
}
</SCRIPT>
<SCRIPT async defer src="https://maps.googleapis.com/maps/api/js?
key=MY_MAP_KEY&callback=initMap">
</SCRIPT>
</BODY>
</HTML>
地图测试
/* --------------------------------------------------- */
/*显式设置贴图高度以定义贴图的大小*/
/*包含映射的DIV*元素*/
/* ----------------------------------------------------*/
#地图{
身高:75%;
边框:5px纯绿色;
}
// --------------------------------------
//以毫秒为单位设置刷新间隔
// --------------------------------------
设置间隔(页面刷新,1*60000);
google.maps.event.addDomListener(窗口“加载”,初始化);
地图演示
var映射;
函数initMap(){
map=new google.maps.map(document.getElementById('map'){
缩放:2,
中心:新google.maps.LatLng(35.4437139.6380),
mapTypeId:'地形'
});
// ---------------------------------------------------------
//创建标记并将USGS URL设置为源。
// ---------------------------------------------------------
var script=document.createElement('script');
// -----------------------------------------------------------------------
//使用存储在USGS服务器上的GeoJSON的本地副本
//
http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_hour.geojsonp
// -----------------------------------------------------------------------
script.src=
'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_hour.geojson
p′;
document.getElementsByTagName('head')[0].appendChild(脚本);
}
// ------------------------------------------------------------------
//循环遍历结果数组,并为每组结果放置一个标记
//坐标。
// ------------------------------------------------------------------
window.eqfeed\u callback=函数(结果){
对于(var i=0;i
虽然不是很优雅,但我使用了以下内容进行刷新。因为我只是建立一个“概念证明”,刷新整个页面不是问题
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
window.onload = timedRefresh(60*5000);
你的问题是什么?发布的代码有什么问题?对不起,我想我的问题很清楚。是的,但只是在我脑子里。我道歉。似乎setInterval不起作用,我不知道为什么。我确认的唯一方法是在设置的刷新时间限制过了很久之后手动刷新页面。我可以做些什么来刷新页面?谢谢你的帮助。