寻找解决方案并尝试了迄今为止我发现的大部分内容。我是谷歌地图和Javascript的新手。希望有人能看到我在这里失踪的东西(并提前感谢你!)。
我直接使用Google Maps Tutorial中的示例。我按照异步加载API的说明进行了大约一半的操作。
我按照规定处理了代码。在页面上创建了div元素,确保了body和div的高度和宽度。在使用调试器逐步执行代码时,它会通过loadScript成功设置DOM上的脚本。然后它在完成后立即失败(看起来似乎)。我可以告诉它,有点看起来初始化函数是未定义的?不确定我需要做什么。
再次,非常感谢帮助/见解。我的额头受伤了;)
{ " name":" movin-there", "私人":是的, "依赖":{ " angular":" ~1.2.28", " json3":" ^ 3.3.0", " angular-bootstrap":" ~0.12.0", " bootstrap":" ~3.2.0", " angular-animate":" ~1.2.28", " angular-cookies":" ~1.2.28", " angular-resource":" ~1.2.28", " angular-route":" ~1.2.28", " angular-sanitize":" ~1.2.28", " angular-touch":" ~1.2.28", " lodash":" ~2.4.1" }, " devDependencies":{ "棱角分明":" ~1.2.28", "角度情景":" ~1.2.28" }, " appPath":" app", "决议":{ "棱角分明":" 1.2.28" } }
//app.js
//
angular.module('MovnThereUI',[
'ui.bootstrap',
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch'
]).run([
'$rootScope',
'$location',
'$http',
'$window',
'AuthFactory',
'UserFactory',
'TypeAheadFactory',
function(
$rootScope,
$location,
$http,
$window,
AuthFactory,
UserFactory,
TypeAheadFactory
) {
'use strict';
$rootScope.$on('$routeChangeStart', function(event, next) {
if (AuthFactory.isAuthenticated()) {
if (AuthFactory.isAuthenticated()) {
$http.defaults.headers.common['Authorization'] = 'Token token=' + $window.sessionStorage.getItem('movnThereUI.user');
}
UserFactory.fetch();
} else {
if (($location.path() !== '/login') && ($location.path() !== '/signup')) {
$location.path('/login');
}
}
});
function initialize() {
debugger;
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644)
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&' +
'callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript;
}
]
);

/* app.css */
html, body, #map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
.nav, .pagination, .carousel, .panel-title a {
cursor: pointer;
}

<!-- index.html -->
</head>
<body ng-app="MovnThereUI">
<ng-include src="'views/partials/navbar.html'"></ng-include>
<ng-view></ng-view>
<div id="map-canvas"></div>
.......snip
&#13;
答案 0 :(得分:0)
只需要我的两分钱,intitialize
应绑定到window
对象,而不管加载gmap脚本的上下文。
所以我想解决这个问题,你可以尝试使用
window.initialize = function(){..}
。但是有些人可能不想要这个!