AngularJs应用中的Google地图api加载/安装失败

时间:2016-06-10 10:52:40

标签: angularjs google-maps google-maps-api-3 ionic-framework

我正在尝试在Angularjs应用中使用Google地图,如下所述:http://angular-ui.github.io/angular-google-maps/#!/use

我遵循了所有步骤,但我收到了以下错误:

enter image description here

我的index.html按以下顺序包含脚本:

if ($_SERVER['REQUEST_METHOD'] == 'POST')

在我的app.js中,我将其配置如下:

<!-- ionic/angularjs js -->
<script src='lib/loadash/dist/lodash.js'></script>
<script src="lib/angular/angular.js"></script>
<script src="lib/angular-messages/angular-messages.js"></script>
<script src="lib/angular-route/angular-route.js"></script>
<script src="lib/angular-cookies/angular-cookies.js"></script>
<script src="lib/angular-sanitize/angular-sanitize.js"></script>
<script src="lib/angular-animate/angular-animate.js"></script>
<script src="lib/ionic/js/ionic.bundle.js"></script>

<script src='lib/angular-simple-logger/dist/angular-simple-logger.min.js'></script>
<script src='lib/angular-google-maps/dist/angular-google-maps.min.js'></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

在我的控制器中:

swarmsApp.config(function($stateProvider, $urlRouterProvider, $httpProvider, uiGmapGoogleMapApiProvider) {

uiGmapGoogleMapApiProvider.configure({
    //    key: 'your api key',
    v: '3.20', //defaults to latest 3.X anyhow
    libraries: 'weather,geometry,visualization'
});

出了什么问题?

更新:通过在.controller('FarmersCtrl', ['$scope','$http', 'uiGmapGoogleMapApi', function($scope, $http, uiGmapGoogleMapApi) { $scope.map = { center: { latitude: 45, longitude: -73 }, zoom: 8 }; 之前加入<script src='//maps.googleapis.com/maps/api/js?sensor=false'></script>来解决此错误但是看起来不是推荐方式。

这导致了另一个错误:

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:1)

缺少图书馆。我认为你需要lodash角谷歌地图。请参阅给定库链接中的代码段:

<script src='/path/to/lodash[.min].js'></script>
<script src='/path/to/angular[.min].js'></script>
<script src='/path/to/angular-simple-logger/angular-simple-logger[.min].js'></script>
<script src='/path/to/angular-google-maps[.min].js'></script>

包括库,然后重试。感谢。

答案 1 :(得分:0)

我推荐这篇文章: http://codepen.io/netsi1964/post/angularjs-google-maps-directive并用

替换了lib文件夹中下载的loadash
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>