私は最近天気アプリを作り続けています。 私は自分のコードと気温をテストしました。現在の天気の国と解説は表示されていません。私は問題が私のhtml geolocation関数の後に始まると思う。私は関数が何らかの形で天気予報データを解析できないと感じています。天気アプリのウェブページにデータが表示されていません
私のコードは、ダウン下にここにある:
$(document).ready(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
function showPosition(position) {
var lat = "lat= " + position.coords.latitude;
var lon = "lon= " + position.coords.longitude;
getWeather(lat,lon);
}
function getWeather(lat,lon){
var urlstring = "https://fcc-weather-api.glitch.me/api/current?" + lat + "&" + lon;
$.ajax({
url : urlstring,
dataType : "jsonP",
success : function(data){
var temp = data.main.temp;
var desc = data.weather[0].description;
var country = data.sys.country;
$("#desc").html(desc);
$("#temp").html(temp);
}
})
}
var ctof = $("#c/f").click(function(){
var cel = Math.round((temp - 32) * 5/9);
var faren = Math.round((temp * 9/5) + 32);
if(ctof == true){
$("#temp").html(faren);
}
else{
$("#temp").html(cel);
}
})
});
は、私もちょうど参照
<!DOCTYPE html>
<html>
<head><title>Web App</title></head>
<body>
<div class="container">
<div class="row">
<header class="col-xs-12 text-center">
<h1>Free Code Camp </h1>
<h1>Weather App</h1>
</header>
<div class="col-xs-8 col-xs-offset-2">
<div class="text-center status">
<p><span id="city"></span> <span id="country"></span></p>
<p><span id="temp"><button id="#c/f">C/F</button></span></p>
<p id="desc"></p>
</div>
<div class ="info">
<div class="develop">Developed by = Shumaila Bi Shaikh</div>
<div class="langs">Created by: HTML,CSS,ANGULARJS</div>
</div>
<script src="Weather.js"></script>
を:そのために行を変更します。 https://jsfiddle.net/bokav0z8/1/を参照してください。問題はHTML構造である可能性があります。 – Luka
@Lukaはい、そうです。そしてボタン**#c/f ** ??? – gaetanoM