Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在谷歌地图信息窗口中加载动画_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 在谷歌地图信息窗口中加载动画

Javascript 在谷歌地图信息窗口中加载动画,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我开发了这个,你可以点击一个地方,从中获取当前天气的详细信息。一切正常,但在点击某个地方显示天气后,会有一点延迟。为此,我想在infowindow中显示一个小的加载动画,在天气数据可用后,它将在同一infowindow中显示天气。如何做到这一点。(这是纯html/js站点,您可以按ctrl+u查看源代码)是。从中获取动画图标,称之为ajaxicon.gif 将您的map单击事件更改为: google.maps.event.addListener(映射,'click',函数(事件){ //调用函数

我开发了这个,你可以点击一个地方,从中获取当前天气的详细信息。一切正常,但在点击某个地方显示天气后,会有一点延迟。为此,我想在infowindow中显示一个小的加载动画,在天气数据可用后,它将在同一infowindow中显示天气。如何做到这一点。(这是纯html/js站点,您可以按ctrl+u查看源代码)

是。从中获取动画图标,称之为
ajaxicon.gif

将您的
map
单击事件更改为:

google.maps.event.addListener(映射,'click',函数(事件){
//调用函数来创建标记
如果(标记){
marker.setMap(空);
标记=空;
}
//你为什么一次又一次地重新创建标记??
marker=createMarker(event.latLng,'name','';
getWeather(event.latLng.lat(),event.latLng.lng(),函数(数据){
infowindow.setContent(“+data.list[0]。name+”
“+data.list[0]。weather[0]。description+”
”; }); });
  • 创建标记,通过
    createMarker
    函数在信息窗口中放置动画ajax图标
  • 成功/回调时,将infowindow内容替换为实际天气内容

  • 您也可以尝试以下方法

    google.maps.event.addListener('click', showLoading);
    
    function showLoading(event) {
      var contentString = '<img src="images/loading.gif">';
    
      infoWindow.setContent(contentString);
      infoWindow.setPosition(event.latLng);
    
      getWeather(event.latLng.lat(),event.latLng.lng(),function (data) {
        contentString = "<b>"+data.list[0].name+"</b><br>"+data.list[0].weather[0].description+"<br><center><img src=http://www.openweathermap.com/img/w/"+data.list[0].weather[0].icon+".png></center>"
        infowindow.setContent(contentString);
      });
    
      infoWindow.open(map);
    };
    
    google.maps.event.addListener('click',showLoading);
    函数显示加载(事件){
    var contentString='';
    setContent(contentString);
    infoWindow.setPosition(event.latLng);
    getWeather(event.latLng.lat(),event.latLng.lng(),函数(数据){
    contentString=”“+数据。列表[0]。名称+“
    ”+数据。列表[0]。天气[0]。说明+“
    ” setContent(contentString); }); 打开(地图); };
    请解释其工作原理(原始代码中有什么错误)