-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (38 loc) · 1.33 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// GET USER LOCATION
if (window.navigator && window.navigator.geolocation) {
window.navigator.geolocation.getCurrentPosition(function(result) {
position = result;
}, function(err) {
// to do, better error
console.log(err);
});
}
// GET WEATHER FOR LOCATION
function getWeather(position) {
$.ajax({
dataType: "jsonp",
url: 'https://api.darksky.net/forecast/648dec742889b2ef905cc950f3f92b67/' + position.latitude + ',' + position.longitude,
success: function(data){
console.log(data);
$('.wi').addClass("wi-forecast-io-" + data.currently.icon);
$('.temperature').html(fToC(data.currently.temperature));
WeatherComponent.setTemperature(fToC(data.currently.temperature));
}
});
}
function getGeolocation(position){
$.ajax({
datatype:"jsonp",
url:"https://maps.googleapis.com/maps/api/geocode/json?latlng=" + position.latitude + ',' + position.longitude + "&key=AIzaSyAP8Ht3jk6woGKIhO6Ok72HgI4Lw_D51dw&result_type=administrative_area_level_3",
success: function(data){
console.log(data);
$('.location').html(data.results[0].formatted_address);
}
});
}
function fToC(fahrenheit)
{
var fTemp = fahrenheit;
var temp = (fTemp - 32) * 5 / 9;
return temp.toFixed(2).toString() + 'c';
}