Fixed location enable.
This commit is contained in:
parent
e9e98d3124
commit
94615fd66e
24
index.html
24
index.html
@ -6,18 +6,13 @@
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
|
||||
<!--END Angular-->
|
||||
<script>
|
||||
var lat = 43.2099824;
|
||||
var lon = -79.9958742;
|
||||
//This needs to be dynamic somehow
|
||||
</script>
|
||||
</head>
|
||||
<body ng-app="mainPage" ng-controller="body">
|
||||
<div class="container">
|
||||
<div class="weather-side">
|
||||
<div class="weather-gradient"></div>
|
||||
<div class="date-container">
|
||||
<h2 class="date-dayname">Today</h2><span class="date-day">DATE</span><span class="location">Ancaster</span>
|
||||
<h2 class="date-dayname">Today</h2><span class="date-day">DATE</span><span class="location">{{readableloc}}</span>
|
||||
</div>
|
||||
<div class="weather-container"><i class="weather-icon" data-feather="sun"></i>
|
||||
<h1 class="weather-temp">{{weather.current.temp}}°C</h1>
|
||||
@ -57,9 +52,24 @@
|
||||
var app = angular.module('mainPage', []);
|
||||
app.controller('body', function($scope, $http) {
|
||||
//Some sort of async function so location is got before the script called
|
||||
$scope.weather = 0
|
||||
// $scope.weather.current.temp = 1;
|
||||
navigator.geolocation.getCurrentPosition((position) => {
|
||||
$scope.loaddata(position.coords.latitude, position.coords.longitude)
|
||||
});
|
||||
$http.get("http://ipinfo.io").then(function (response) { // Easier way to grab location name via IP
|
||||
$scope.readableloc = response.data.city + ', ' + response.data.region;
|
||||
|
||||
})
|
||||
$scope.loaddata = function(lat, lon) {
|
||||
$http.get("https://api.openweathermap.org/data/2.5/onecall?lat=" + lat + "&lon=" + lon + "&units=metric&appid=5292f0a17ecbe4b523fe0609ed2c556f").then(function (response) {
|
||||
$scope.weather = response.data;
|
||||
$scope.lat = lat;
|
||||
$scope.lon = lon;
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
Loading…
Reference in New Issue
Block a user