在angularjs ng-repeat中,我必须使用谷歌地图显示设备到地点之间的距离。我正在分享我所做的代码,但它不工作,但当我在断点检查它时,它得到了距离,但没有在占位符"{{ Show_Distance(place3,place4) }}“中更新。
HTML页面:
<ons-row ng-repeat="place in PlacesList" style="border-bottom:solid 6px orange;">
<ons-col>
<ons-button modifier="clean" ng-click="showPlacesDetails($index)">
<img src="{{ place[1] }}">
<div style="position:absolute; bottom:0; width:100%;">
{{ Show_Distance(place[3], place[4]) }}
</div>
</ons-button>
</ons-col>
在Controller js文件中:
$scope.Show_Distance = function (lat, lng) {
var Distance = Get_Distance(lat, lng);
return Distance;
};
function Get_Distance(lat, lng) {
//*********DISTANCE AND DURATION**********************//
var Distance = 'Distance: N.A.';
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix({
origins: [new google.maps.LatLng($rootScope.deviceLatitude, $rootScope.deviceLongitude)],
destinations: [new google.maps.LatLng(lat, lng)],
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false
},
function (response, status) {
if (status == google.maps.DistanceMatrixStatus.OK && response.rows[0].elements[0].status != "ZERO_RESULTS") {
Distance = response.rows[0].elements[0].distance.text;
//alert(Distance);
}
});
return Distance;
}帮助将会得到评价。
编辑: PlacesList contsins(1位):
<Value><string>1</string><string>Forresta Kitchen & Bar</string><string>Forresta Kitchen is nice place</string><string>26.920979</string><string>75.793934</string><string>4</string><string>images/PlacesMedia/1_01.jpg</string></Value>发布于 2016-06-03 16:42:14
你试图得到经度和纬度之间的距离,这没有任何意义,你必须使用两个点,每个点都有自己的经度和纬度,然后计算距离。这是一个实际的例子:x:经度y:纬度

https://stackoverflow.com/questions/32499313
复制相似问题