Click here to Skip to main content
15,891,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<html>
<head>
  <link rel="stylesheet" href="style.css">
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
 <script src="ng-haversine.min.js"></script>
 <script src="package.json"></script>
</head>
<body ng-app="myNgApp">
<h1>AngularJS $scope Demo: </h1>
    <div ng-controller="myController">
      {{distance}}
      </div>
       <script>
        var ngApp = angular.module("myNgApp",["dahr.ng-haversine"]);

        ngApp.controller('myController', function ($scope) {
          var coord1 = {
  "latitude": 40.4169473,
  "longitude": -3.7057172
};
var coord2 = {
  "latitude": 40.4236942,
  "longitude": -3.7109793
};
var distance = $haversine.distance(coord1, coord2);
            $scope.distance=distance ;        
        });
    </script>
</body>


What I have tried:

I tried by using ng-haversine module .below is the script of ng-haversine.
// Code goes here

/**
 * @name ng-haversine
 * @version 0.0.1
 * @license MIT
 * @author Diego Herrera
 * @description ng-haversine is an AngularJS module that applies the Haversine formula to a pair of coordinates to calculate the distance between them.
 */

!function(t){"use strict";t&&t.angular?angular.module("dahr.ng-haversine",[]).service("$haversine",function(){var t=6378137,a=function(t){return t*Math.PI/180};this.distance=function(n,e){var r=a(e.latitude-n.latitude),i=a(e.longitude-n.longitude),o=Math.pow(Math.sin(r/2),2)+Math.cos(a(n.latitude))*Math.cos(a(e.latitude))*Math.pow(Math.sin(i/2),2),s=2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o));return t*s}}):t.console.error("ng-haversine: AngularJS must be loaded first. More info at https://angularjs.org/.")}(window);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900