我正在使用带有angularjs的MVC 5 Web应用程序。有谷歌地图。
在我的Angular视图中,我使用app.js
中的指令进行谷歌地图。
请参阅下面的代码。
app.js
myApp.directive('googlemap', function ($compile) {
return {
controller: function ($scope) {
var map;
this.registerMap = function (myMap) {
var center = myMap.getCenter(),
latitude = center.lat(),
longitude = center.lng();
//zoom = center.zoom();
map = myMap;
$scope.latitude = latitude;
$scope.longitude = longitude;
$scope.zoom = map.getZoom();
};
$scope.$watch('latitude + longitude', function (newValue, oldValue) {
if (newValue !== oldValue) {
var center = map.getCenter(),
latitude = center.lat(),
longitude = center.lng();
if ($scope.latitude !== latitude || $scope.longitude !== longitude)
map.setCenter(new google.maps.LatLng($scope.latitude, $scope.longitude));
}
});
},
link: function (scope, elem, attrs, ctrl) {
var mapOptions,
latitude = attrs.latitude,
longitude = attrs.longitude,
//controlTemplate,
//controlElem,
map;
// parsing latLong or setting default location
latitude = latitude && parseFloat(latitude, 10) || 43.074688;
longitude = longitude && parseFloat(longitude, 10) || -89.384294;
mapOptions = {
zoom: 8,
disableDefaultUI: true,
center: new google.maps.LatLng(latitude, longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(elem[0], mapOptions);
ctrl.registerMap(map);
function centerChangedCallback(scope, map) {
return function () {
var center = map.getCenter();
scope.latitude = center.lat();
scope.longitude = center.lng();
scope.zoom = map.getZoom();
if (!scope.$$phase) scope.$apply();
};
}
google.maps.event.addListener(map, 'center_changed', centerChangedCallback(scope, map));
}
};
});
HTML
<div style="height:400px;" googlemap latitude="43.074688" longitude="-89.384294"></div>
它在本地主机上运行良好。但是当我在网络服务器上托管这个页面时,
Google Chrome控制台中显示错误:
我发现两个页面的view-source:
存在差异(本地主机和托管
页)。本地主机和托管页面中的脚本引用最少。
请您就此问题提出任何建议吗?
答案 0 :(得分:1)
您好我很确定问题是加载您的脚本,交叉检查您在主机中的脚本位置。