Member 13318943 Ответов: 0

Вычисление расстояния между двумя координатами в angularjs


<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>


Что я уже пробовал:

Я попробовал использовать модуль ng-haversine .ниже приведен сценарий 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);

0 Ответов