【发布时间】:2014-02-23 08:59:35
【问题描述】:
我正在尝试将我从 API 获得的天气图标更改为我自己在 Photoshop 上绘制的图标!我的变量是法语和 cmets,如果您需要翻译来理解我的代码,请询问!
<script type="text/javascript">
jQuery(document).ready(function($) {
var maLatitude; /*Variable gobale contenant la latitude*/
var maLongitude; /*Variable gobale contenant la longitude*/
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(showPosition);
else
alert("Votre navigateur supporte pas la géolocalisation, essayez de mettre à jour votre navigateur!");
});
function showPosition(position){
maLatitude= position.coords.latitude;
maLongitude= position.coords.longitude;
$.ajax({
url : "http://api.wunderground.com/api/API_KEY/geolookup/conditions/lang:FC/q/"+maLatitude+","+maLongitude+".json",
dataType : "jsonp",
success : function(parsed_json) {
var location = parsed_json['location']['city'];
var temp_c = parsed_json['current_observation']['temp_c'];
var tempRessentie = parsed_json['current_observation']['feelslike_c'];
var wicon = parsed_json['current_observation']['icon'];
var condition = parsed_json['current_observation']['weather'];
var vent_kmh = parsed_json['current_observation']['wind_kph'];
var rafales = parsed_json['current_observation']['wind_gust_kph'];
var visibilite = parsed_json['current_observation']['visibility_km'];
$("div.ville").append("<div class='endroit'>" + location + " </div>"+
"<div class='temp'>" + temp_c + " °C</div>"+
"<div> Temp. ressentie : "+tempRessentie+" °C</div>"+
"<div class='triangle'></div>"+
"<div class='icone'><img src='http://icons-ak.wxug.com/i/c/k/"+wicon+".gif' alt='"+condition+"' title='"+condition+"'/></div>"+
"<div class='condition'>"+condition+"</div>"+
"<div>Vent : "+vent_kmh+" km/h</div>"+
"<div>Rafales : "+rafales+" km/h</div>"+
"<div>Visibilité : "+visibilite+" km</div>");
}
});
}
</script>
【问题讨论】:
-
那么问题是什么?只需将
imgsrc更改为您想要的任何内容。 -
但是如果我把它改成另一个 src 它只会给我一个特定的天气图标,除非有另一种我没想到的方法? :O
-
基本上根据当天的天气情况,加载页面时会出现不同的天气图标!但是我自己画了几个天气图标,我希望能够根据当天的天气加载它们!
-
您需要与它们具有相同的文件名,或者自己将它们映射到您想要使用的任何内容。所以如果他们有
sunny.gif,你就有sunny.gif,你唯一改变的部分就是你的服务器的路径。 -
哦,非常感谢!!!那行得通! :D:D:D:D:D 我无法表达我有多高兴!!谢谢谢谢谢谢!!
标签: javascript json html api weather-api