【问题标题】:Google weather library谷歌天气库
【发布时间】:2013-01-21 12:41:58
【问题描述】:

我正在使用 Google 图书馆时间在地图上显示它。

我遇到的问题是显示的第一个窗口非常小,您必须滚动。 如何控制这个窗口的大小?

其次,我只想显示我提供的坐标的地图,并显示我想要的最短时间。我该怎么做?

这是我在here中的代码:

         function generartiempo(36.745,-3.87665,'mapatiempo') {
            var mapOptions = {
          zoom: 11,
          center: new google.maps.LatLng(lat,lng,true),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var infowindow = new google.maps.InfoWindow();
        var map = new google.maps.Map(document.getElementById('mapatiempo'),
            mapOptions);

        var weatherLayer = new google.maps.weather.WeatherLayer({
          temperatureUnits: google.maps.weather.TemperatureUnit.CELSIUS,
          windSpeedUnit: google.maps.weather.WindSpeedUnit.KILOMETERS_PER_HOUR
        });


        weatherLayer.setMap(weatherLayer.getMap() ? null : map);

        var cloudLayer = new google.maps.weather.CloudLayer();
        cloudLayer.setMap(map);

    }
<div id="mapatiempo"></div>
#mapatiempo {
width: 268px;
height: 200px;
border: 1px solid #AAAAA8;
margin-bottom: 5px;
margin-top: 15px;
}

有人可以帮忙吗? 编辑示例:http://jsfiddle.net/webyseo/YW2K7/12/ 解决方案? 谢谢!!!!!!

【问题讨论】:

标签: google-maps-api-3 weather


【解决方案1】:

没有定义默认信息窗口大小的选项。而且infoWindow的大小受地图大小的限制,不能变大,所以需要放大地图。

您可以做什么:使用自定义 infoWindow 覆盖默认 infoWindow 并自行定义内容,使其适合较小的 infoWindow


自定义信息窗口的示例代码:(假设变量包含google.maps.Map

    //create the weatherLayer
    var weatherLayer = new google.maps.weather.WeatherLayer({
      temperatureUnits: google.maps.weather.TemperatureUnit.FAHRENHEIT,
      clickable:true,
      suppressInfoWindows:true
    });

    //create InfoWondow-instance
    var weatherWindow=new google.maps.InfoWindow();

    //observe click-event
    google.maps.event.addListener(weatherLayer,'click',function(e){

      //hide infoindow
      weatherWindow.close();

      var content  = document.createElement('ul'),
          weather  = e.featureDetails.forecast,
          unit     = '°'+e.featureDetails.temperatureUnit.toUpperCase();

        //merge current weather and forecast
        weather.push(e.featureDetails.current);

        //create some content(here a short summary)
        for(var i = 0; i<weather.length; ++i){
          var item = content.appendChild(document.createElement('li'))
                      .appendChild(document.createTextNode(''))
              w    = weather[i];
              item.data='['+w.shortDay+']'+w.description+
                        '('+w.low+unit+'/'+w.high+unit+')';


        }
        //set content and position of the infoWindow
        weatherWindow.setOptions({position:e.latLng,content:content});
        //...and open the infowindow
         weatherWindow.open(map);
    });
    weatherLayer.setMap(map);

演示:http://jsfiddle.net/doktormolle/pnAyD/

【讨论】:

  • 非常感谢你是我所担心的。您知道我如何获取图像,例如:太阳并覆盖默认窗口信息
  • 太阳/云/地图上的任何东西都不是图像,它们是图块的一部分,因此您无法将它们作为单个图像获取(但您可以单击它们,API 将点击响应)。要获取自定义 infoWindows,请将 weatherlayer 的 suppressInfoWindows-option 设置为 true 并观察 weatherLayer 的点击事件。当点击发生时,传递给点击回调的参数包含该位置的天气特征,您可以使用它们为文档中定义的 infoWindow 创建内容。
  • 再次感谢您,我只是不明白如何获得马赛克的那部分。如果不是太多,你能给我举个例子吗?谢谢!!!
  • 天哪,我爱你。非常感谢您。我欠你一个人情。一个拥抱。
猜你喜欢
  • 2011-07-30
  • 2012-05-17
  • 1970-01-01
  • 2011-06-25
  • 2011-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多