我添加了我的代码。我有经纬度的移动商店列表。在这里,我计算了特定点到所有商店之间的距离,我在控制台中显示,但我想将该值(_d
)推送到每个商店。请有人帮助我。
目前,它只是显示:
Adtiya Samsung Store
aditiya@gmail.com
sri shakthi mobile service
rajs@gmail.com
sun mobile service center
sprtive23@gmail.com
ragu mobile service center
super@gmail.com
请有人帮我更新此S_clocation。我在这里苦苦挣扎,因为我对这项技术不熟悉。
http://jsfiddle.net/rpbn6u23/16/
angular.module('myApp', [])
.controller("myCntrl", function ($scope) {
//$scope.query = " Regular Service,Hardware Faults,overall maintenance";
$scope.dealers = [{
S_Email_id: "aditiya@gmail.com",
S_Store: "samsung",
Store_Name: "Adtiya Samsung Store",
S_Services: "Regular Service,Software Faults,Hardware Faults",
Store_long_description: "Undertake all kind of samsung mobiles",
Store_short_description: "Undertake all kind of samsung mobiles",
S_Latitude: "12.93489905",
S_Longitude: "77.57070772",
S_clocation: ""
}, {
S_Email_id: "rajs@gmail.com",
S_Store: "nokia",
Store_Name: "sri shakthi mobile service",
S_Services: "Settings Faults,Regular Service,Hardware Faults",
Store_long_description: "Undertake all kind of nokia mobiles",
Store_short_description: "Undertake all kind of nokia mobiles",
S_Latitude: "12.9599264",
S_Longitude: "77.5924983",
S_clocation: ""
}, {
S_Email_id: "sprtive23@gmail.com",
S_Store: "nokia,samsung",
Store_Name: "sun mobile service center",
S_Services: "Regular Service,overall maintenance,Mobile Shield Installation",
Store_long_description: "Undertake all kind of nokia,samsung mobiles",
Store_short_description: "Undertake all kind of nokia,samsung mobiles",
S_Latitude: "12.911229",
S_Longitude: "77.519281",
S_clocation:""
},
{
S_Email_id: "super@gmail.com",
S_Store: "nokia,samsung",
Store_Name: "ragu mobile service center",
S_Services: "Regular Service,overall maintenance,Mobile Shield Installation",
Store_long_description: "Undertake all kind of nokia,samsung mobiles",
Store_short_description: "Undertake all kind of nokia,samsung mobiles",
S_Latitude: "12.909999",
S_Longitude: "77.506871",
S_clocation: ""
}
]
var _lat1 =12.904778 ;
var _lon1 =77.585680;
var d = $scope.dealers.length;
for (var i = 0; i < d; i++) {
var _lat2 = $scope.dealers[i].S_Latitude;
var _lon2 = $scope.dealers[i].S_Longitude;
//--------------------------------------distance calculation-------------------------------------
function _getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
var R = 6371; // Radius of the earth in kilometers
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
return d;
}
function deg2rad(deg) {
return deg * (Math.PI / 180)
}
// precise value
var _d = "Precise value: " + _getDistanceFromLatLonInKm(_lat1, _lon1, _lat2, _lon2);
_d = Math.round(_getDistanceFromLatLonInKm(_lat1, _lon1, _lat2, _lon2) * 100) / 100;
console.log(_d);
//-----------------------------------------------------------------------------------------------
}
}
)
&#13;
<div ng-app="myApp">
<div ng-controller="myCntrl">
<label>Case sensitive Search on Label</label><br>
<input ng-model="query" type="text" placeholder="Search for name" />
<div ng-repeat="dealer in dealers">
{{dealer.Store_Name}}<br>
{{dealer.S_Email_id}}<br>
{{dealer.S_clocation}}<br>
</div><br><br><br>
</div>
</div>
&#13;
答案 0 :(得分:0)
您已经在循环中引用了经销商对象:$scope.dealers[i].distance = _d;
。只需向该对象添加另一个属性即可。
{{dealer.distance}}
然后,您可以像显示其他属性一样在页面上显示它。
$( ".rateThis span" ).click(function() {
$('.rateThis').before().append('<i class="fa fa-star"></i>');
});
查看更新的fiddle。