Как я могу добавить геолокацию погоды на моем сайте? - PullRequest
1 голос
/ 25 февраля 2020

Я хочу добавить погоду на моем сайте. Я пытался сделать это с json и jquery, но у меня есть некоторые проблемы. Вы можете мне помочь или посоветовать другой способ сделать это, пожалуйста? проблема в том, что в консоли показывают, что эти json ссылки, которые у меня есть на странице html, являются неправильными. пожалуйста, помогите мне. что я могу сделать?

вот мой код




if("geolocation" in navigator){
   navigator.geolocation.getCurrentPosition(function(position){
       loadweather(position.coords.latitude + "," + position.coords.longitude);
   });
}else {
    loadweather("kolkata, in" );
}

$(document).ready(function(){
    setInterval(getWeather, 10000);
});

function loadWeather (location, woeid){
    $.simpleWeather({
        location:location,
        woeid:woeid,
        unit:'c',
        suncess:function(weather){
            city = weather.city,
            temp = weather.temp+'°';
            wcode = '<img class="weathericon" src=images/weathericons/' + weather.code + '.svg';
            wind = '<p>' + weather.wind.speed + '</p><p>' + weather.units.speed +'</p>';
            humidity = weather.humidity + '%';
            $(".location").text(city);
            $(".temperature").html(temp);
            $(".climate_bg").html(wcode);
            $(".windspeed").html(wind);
            $(".humidity").text(humidity);
        },
        error: function(error) {
            $(".error").html('<p>' + error + '</p>');
        }
    });
}







<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1.0">
  <title>Weather App</title>
  <link href="http://fonts.googleapis.com/css?family=Montserrat:400,700,inherit,400" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="css/standardize.css">
  <link rel="stylesheet" href="css/index.css">
</head>
<body class="body page-index clearfix">
  <div class="container clearfix">
    <p class="location"></p>
    <p class="temperature"></p>
    <div class="climate_bg"></div>
    <div class="info_bg">
      <img class="dropicon" src="images/Droplet.svg">
      <p class="humidity"></p>

      <img class="windicon" src="images/Wind.svg">
      <div class="windspeed"></div>
    </div>
  </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/3.1.0/jquery.simpleWeather.min.js"></script>
 <script src="js/script.js"></script>

</body>
</html>



Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...