2012-03-12 156 views
2

我們如何在谷歌地圖上添加天氣覆蓋選項,就像在我的Google地圖上一樣? 我搜索了它,但我找不到答案。谷歌地圖api v3天氣信息

我必須打電話給天氣網站服務嗎?

+1

WeatherLayer不再http://googlegeodevelopers.blogspot.com.au/2014/06/sunsetting-javascript-api-weather-panoramio.html – yulie 2016-01-13 00:38:45

回答

3

你可以走兩步你的地圖上顯示WeatherLayer dev-guide

首先,通過將libraries參數,您使用的網址加載地圖加載WeatherLayer庫:

<script type="text/javascript" 
    src="http://maps.googleapis.com/maps/api/js?libraries=weather&sensor=false"> 
</script> 

然後,您必須創建一個類的實例,傳遞WeatherLayerOptionsapi-doc對象中的任何選項,並將WeatherLayer附加到地圖上:

var weatherLayer = new google.maps.weather.WeatherLayer({ 
    temperatureUnits: google.maps.weather.TemperatureUnit.FAHRENHEIT 
}); 
weatherLayer.setMap(map); 

除了WeatherLayer,還有一個單獨的google.maps.weather.CloudLayerapi-doc類,您可以用類似的方式創建:

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

沒有,你必須加載使用的CloudLayer獨立的庫;將libraries=weather參數添加到加載地圖的URL會使WeatherLayer和CloudLayer在您的地圖上可用。作爲Google Maps JavaScript API v3 Example: Weather Layer,顯示了這兩個層的用法。

1

當我嘗試將Google地圖apiv3與天氣圖層一起使用時,我遇到了同樣的麻煩。但幸運的是,我發現這個網站http://code.google.com/p/gmaps-samples-v3/,提供所有谷歌地圖api v3樣品,他們的工作。希望這個幫助。

的Cuong VO

+0

請在您的文章中添加相關的代碼。 – 2013-06-08 18:25:11