$http.get('*****').success(function(data,dealers,response)
{
$scope.items = data;
$scope.item ='';
console.log(data);
var shoplatit=data.S_Location.Latitude;
var shoplong=data.S_Location.Longitude;
\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t
});
$scope.nearme = function($scope) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
mysrclat = position.coords.latitude;
mysrclong = position.coords.longitude;
console.log(mysrclat);
console.log(mysrclong);
});
}
i tried like this but its not working getting deg2rad is not defined erro
var lat1 =15.008809;
var lat2 =78.659096;
var lon1 =13.90457539;
var lon2 =78.5855514
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
console.log(d);
<div ng-controller="ListingCtrl" >
<div data-ng-init="nearme()">
<div class="list card" data-ng-repeat="item in items">
<h2>{{item.Store_Name}} </h2>{{item.S_Location.Latitude}}<br>{{item.S_Location.Longitude}}
<p>{{item.S_Address}}</p>
<h1>here i want show distance in km</h1>
</div>
</div>
</div>
我已經存儲了商店的緯度和經度在MongoDB中。在列表頁面中,我使用navigator.geolocation.i獲取客戶緯度和語言。我想計算兩個經度和緯度之間的距離。我已附上我的代碼
感謝它的工作,但我想在該項目中顯示距離我已經在html中提到如何做到這一點,請幫助我 –