Languages

Menu
Sites
Language
Weather data

Hey guys,

i want use weather info in my gear s2 watchface,  how i can access to default weather app data ? anyone can help me?

Thanks in advance

Edited by: aMir Sirati on 27 May, 2016
View Selected Answer

Responses

2 Replies
Mark as answer
Masum Talukder

Hello,

I did not find any default weather app in tizen. But In my opinion, you can use any available Weather API. You can see this post as useful: https://developer.tizen.org/ko/forums/web-application-development/free-weather-and-forecast-api-tizen-applications

And I have tested one sample and sharing with you in below:

var canvas, ctx, clockRadius, isAmbientMode, temparature;

window.requestAnimationFrame = window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    function(callback) {
        'use strict';
        window.setTimeout(callback, 1000 / 60);
    };

function renderDots() {
    'use strict';

    var dx = 0,
        dy = 0,
        i = 1,
        angle = null;

    ctx.save();

    // Assigns the clock creation location in the middle of the canvas
    ctx.translate(canvas.width / 2, canvas.height / 2);

    // Assign the style of the number which will be applied to the clock plate
    ctx.beginPath();

    ctx.fillStyle = '#999999';

    // Create 4 dots in a circle
    for (i = 1; i <= 4; i++) {
        angle = (i - 3) * (Math.PI * 2) / 4;
        dx = clockRadius * 0.9 * Math.cos(angle);
        dy = clockRadius * 0.9 * Math.sin(angle);

        ctx.arc(dx, dy, 3, 0, 2 * Math.PI, false);
        ctx.fill();
    }
    ctx.closePath();

    // Render center dot
    ctx.beginPath();

    ctx.fillStyle = '#ff9000';
    ctx.strokeStyle = '#fff';
    ctx.lineWidth = 4;

    ctx.arc(0, 0, 7, 0, 2 * Math.PI, false);
    ctx.fill();
    ctx.stroke();
    ctx.closePath();
}

function renderAmbientDots() {
    'use strict';

    ctx.save();

    // Assigns the clock creation location in the middle of the canvas
    ctx.translate(canvas.width / 2, canvas.height / 2);

    // Render center dot
    ctx.beginPath();

    ctx.fillStyle = '#000000';
    ctx.strokeStyle = '#fff';
    ctx.lineWidth = 4;

    ctx.arc(0, 0, 7, 0, 2 * Math.PI, false);
    ctx.fill();
    ctx.stroke();
    ctx.closePath();
    ctx.fillText(temparature,canvas.width/2, canvas.height/2);
}

function renderNeedle(angle, radius) {
    'use strict';
    ctx.save();
    ctx.rotate(angle);
    ctx.beginPath();
    ctx.lineWidth = 4;
    ctx.strokeStyle = '#fff';
    ctx.moveTo(6, 0);
    ctx.lineTo(radius, 0);
    ctx.closePath();
    ctx.stroke();
    ctx.closePath();
    ctx.restore();
    ctx.fillText(temparature,canvas.width/2, canvas.height/2);

}

function renderHourNeedle(hour) {
    'use strict';

    var angle = null,
        radius = null;

    angle = (hour - 3) * (Math.PI * 2) / 12;
    radius = clockRadius * 0.55;
    renderNeedle(angle, radius);
    ctx.fillText(temparature,canvas.width/2, canvas.height/2);
}

function renderMinuteNeedle(minute) {
    'use strict';

    var angle = null,
        radius = null;

    angle = (minute - 15) * (Math.PI * 2) / 60;
    radius = clockRadius * 0.75;
    renderNeedle(angle, radius);
    ctx.fillText(temparature,canvas.width/2, canvas.height/2);
}

function getDate() {
    'use strict';

    var date;
    try {
        date = tizen.time.getCurrentDateTime();
    } catch (err) {
        console.error('Error: ', err.message);
        date = new Date();
    }

    return date;
}

function watch() {
    'use strict';

    if (isAmbientMode === true) {
        return;
    }

    // Import the current time
    // noinspection JSUnusedAssignment
    var date = getDate(),
        hours = date.getHours(),
        minutes = date.getMinutes(),
        seconds = date.getSeconds(),
        hour = hours + minutes / 60,
        minute = minutes + seconds / 60,
        nextMove = 1000 - date.getMilliseconds();

    // Erase the previous time
    ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);

    renderDots();
    renderHourNeedle(hour);
    renderMinuteNeedle(minute);

    ctx.restore();
    ctx.fillText(temparature,canvas.width/2, canvas.height/2);
    setTimeout(function() {
        window.requestAnimationFrame(watch);
    }, nextMove);
}

function ambientWatch() {
    'use strict';

    // Import the current time
    // noinspection JSUnusedAssignment
    var date = getDate(),
        hours = date.getHours(),
        minutes = date.getMinutes(),
        seconds = date.getSeconds(),
        hour = hours + minutes / 60,
        minute = minutes + seconds / 60;

    // Erase the previous time
    ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
    ctx.fillText(temparature,canvas.width/2, canvas.height/2);

    renderAmbientDots();
    renderHourNeedle(hour);
    renderMinuteNeedle(minute);

    ctx.restore();
}

function getWeather() {
    'use strict';

    console.log( "ready!" );
      $.ajax({
        type: "GET",
        dataType: "jsonp",
        jsonp: "callback", jsonpCallback: "callback",
        url: "http://apidev.accuweather.com/currentconditions/v1/28143.json?language=en&apikey=hoArfRosT1215",
        cache: false,
        success: function (data) {
             // document.getElementById("results").innerHTML=JSON.stringify(data[0].WeatherText);
        	  temparature = JSON.stringify(data[0].WeatherText);
        	  ctx.font = "30px Comic Sans MS";
        	  ctx.fillStyle = "red";
        	  ctx.textAlign = "center";
        	  
              ctx.fillText(temparature,canvas.width/2, canvas.height/2);
         }
   });
}

window.onload = function onLoad() {
    'use strict';
    
    getWeather();
    canvas = document.querySelector('canvas');
    ctx = canvas.getContext('2d');
    clockRadius = document.body.clientWidth / 2;

    // Assigns the area that will use Canvas
    canvas.width = document.body.clientWidth;
    canvas.height = canvas.width;

    // add eventListener for tizenhwkey
    window.addEventListener('tizenhwkey', function(e) {
        if (e.keyName === 'back') {
            try {
                tizen.application.getCurrentApplication().exit();
            } catch (err) {
                console.error('Error: ', err.message);
            }
        }
    });

    // add eventListener for timetick
    window.addEventListener('timetick', function() {
        console.log("timetick is called");
        ambientWatch();
    });

    // add eventListener for ambientmodechanged
    window.addEventListener('ambientmodechanged', function(e) {
        console.log("ambientmodechanged : " + e.detail.ambientMode);
        if (e.detail.ambientMode === true) {
            // rendering ambient mode case
            isAmbientMode = true;
            ambientWatch();

        } else {
            // rendering normal case
            isAmbientMode = false;
            window.requestAnimationFrame(watch);
        }
    });

    // normal case
    isAmbientMode = false;
    window.requestAnimationFrame(watch);
};

 

If you find my post helpful for you, please mark it as the Best Answer to promote this post to others.

thanks.

 

aMir Sirati

thank you very much br