我正在尝试从服务文件中调用位置坐标并在谷歌地图视图中显示。但是由于某种原因,数据绑定不起作用,并且没有错误,并且控制器正在从服务中调用对象。
我认为我的地图模板中有一些错误,但我无法找出它是什么。有人可以帮我解决这个问题吗?谢谢你。
代码如下:
地图模板
<div class="panel6 panel-primary">
<div class="panel-heading">Truck's Location</div>
<div class="panel-body">
<ng-map zoom="11" center="[49.8994, -97.1392]">
<marker position="[{{maploc.longitude}}, {{maploc.latitude}}]" />
<shape name="circle" center="[{{maploc.longitude}}, {{maploc.latitude}}]" radius="4000" />
<control name="overviewMap" opened="true" />
</ng-map>
</div>
</div>
服务文件
"use strict";
angular.module("fleetListModule").service("fleetsService",
function () {
this.getTrucks = function () {
return trucks;
};
var trucks = [
{
"iD": "1",
"status": "Running",
"destination": "WPG",
"alerts": "Nothing",
"longitude": "49.8994",
"latitude": "-98.1392"
}
];
});
控制器
"use strict";
angular.module("fleetMapModule").controller("fleetMapController",
['$scope', 'fleetsService',
function ($scope, fleetsService) {
$scope.$on('obtainMapLocation', function (event, map) {
var fleetMapLocs = fleetsService.getTrucks();
for (var i = 0; i < fleetMapLocs.length; i++) {
var fleetMapLoc = fleetMapLocs[i];
if (fleetMapLoc.iD == map.id) {
$scope.maploc = fleetMapLoc;
break;
}
}
});
}]);