【发布时间】:2012-07-08 22:49:19
【问题描述】:
有谁知道是否有办法在 Google Maps javascript API 中刷新天气层?
为了提供一些背景知识,我们有一个应用程序在浏览器中保持打开状态,并每隔几分钟更新地图上的一些信息。我们让用户在地图上打开天气图层,但天气只在创建图层时加载一次。一段时间后,它会过时,我们希望它保持最新状态。我已经尝试了一切,从重新创建图层并将地图设置为 null,然后返回到当前地图,但温度从未重新加载。
任何建议都会有帮助。谢谢!
更新: 一些代码 sn-ps 显示我如何尝试重新加载天气层。
//Global variable for the weather layer
var weatherLayer = null;
//When user clicks the weather button on the map
weatherLayer = new google.maps.weather.WeatherLayer({..});
weatherLayer.setMap(myMap);
//When I try to refresh the layer
weatherLayer.setMap(null); //This successfully hides it
weatherLayer = new google.maps.weather.WeatherLayer({...});
weatherLayer.setMap(myMap); //This doesnt' reload the data.
//Tried resetting the options before and after recreating the layer to see if that would help, but it didn't
weatherLayer.setOptions({..new option set..});
【问题讨论】:
-
您能否包含用于尝试更新 WeatherLayer 的代码?我认为如果您包含代码,它可能会允许其他人帮助您找到解决方案。
-
肖恩,我已经用一些代码 sn-ps 更新了这个问题。不知道他们会如何提供帮助,但我真的希望他们能提供帮助。感谢您的回复。
-
这个question and answer 可以帮助你。
-
谢谢,亚历克斯,但不幸的是它没有帮助。天气仍然没有刷新。
-
决定创建一个测试页面以防有人想玩:jsfiddle.net/EbHu9
标签: javascript google-maps-api-3