weather info

by Samar Pattanayak

HTML

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDhkBhtFtJYnkn4lKfC17BLF185JkUIE78"></script>
<div ng-app="myModule">
  <div ng-controller="myController">
    {{title}}
    <input type="button" value="click" ng-click="getLocation()" />
    <p>
      Latitude : <span id="spanlat" ng-bind="lat" style="color:orange"></span>
    </p>
    <p>
      Longitude : <span id="spanlng" ng-bind="lng" style="color:green"></span>
    </p>

  </div>
</div>

JavaScript

var app = angular.module("myModule", []);
app.config(function($sceDelegateProvider,$httpProvider){
	$sceDelegateProvider.resourceUrlWhitelist(['self','http://api.openweathermap.org/**']);
  $httpProvider.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
  $httpProvider.defaults.useXDomain = true;
})
app.controller("myController", function($scope, locService, $rootScope,$sce) {
  $scope.title = "Checking Deorator" + " --> ";
  //console.log(myService.fn_config_decorator());
  $scope.Url= $sce.trustAsUrl("http://api.openweathermap.org/data/2.5/weather");
  console.log($scope.Url);
  $scope.trustedUrl=$sce.getTrustedUrl($scope.Url);
  $scope.getLocation = function(trustedUrl) {
    locService.getLocation();
    locService.weatherinfo($scope.trustedUrl);
    //$scope.lat = $rootScope.lat
  }

})
app.service("locService", function($http) {
  this.showPosition = function(position) {
  document.querySelector("#spanlat").innerHTML = position.coords.latitude;
  document.querySelector("#spanlng").innerHTML = position.coords.longitude;
  };
  this.getLocation = function() {
    if (navigator.geolocation) {
      var cor = navigator.geolocation.getCurrentPosition(this.showPosition);
    } else {
      x.innerHTML = "Geolocation is not supported by this browser.";
    }
  };
  this.weatherinfo = function(urlR) {
  	//var trustedUrl = $sce.trustAsResourceUrl("http://api.openweathermap.org/data/2.5/weather");
    console.log(urlR)
    $http({
      method: 'GET',
      url: 'http://api.openweathermap.org/data/2.5/weather',
      params: {
        lat: "12.9433004",
        lon: "77.6958416",
        appid: "f451f3c04a58a02eb410e9392382d97b"
      }
    }).then(function(data) {
      console.log(data)
    },function(error){
    	console.log(error);
    })
  }
})