Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function(){
- $.getJSON('https://ipinfo.io',function(data){
- //z data dostanes gps,mesto,štat,ipcku... debugni si to a uvidíš čo všetko sa v tom objekte nachádza
- var gps = data.loc;
- var loc = gps.split(',');
- //na zistenie pocasia potrebujes vlastny google api key a zadavas do requestu gps suradnice lat a lon
- $.getJSON('http://api.openweathermap.org/data/2.5/weather? lat='+loc[0]+'&lon='+loc[1]+'&APPID=d0392f67ebcff342709e4e36cbb00878',function(wd){
- //z wd dostanes zase plnu picu informacii
- var icon = wd.weather[0].icon;
- var iconSrc = 'http://api.openweathermap.org//img/w/' + icon + '.png';
- var weather = wd.weather[0].description;
- var temperature = wd.main.temp_max - 273.15;
- // DIV ID = '1'
- //vytvara obrazok v divku
- $('#1').prepend('<img src = '+iconSrc+'><p>Location : '+wd.name +'</p><p>Weather : '+weather+'</p><p>Temperature : '+temperature+'</p>');
- })
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement