相关疑难解决方法(0)

TypeError:window.initMap不是函数

我正在按照本教程,基本上复制所有代码

https://developers.google.com/maps/documentation/javascript/tutorial

但得到一个错误,说initMap函数不是一个函数.我在我的项目中使用angularjs,这可能导致问题吗?

我将相同的代码复制到plunker中,它工作得很好......有什么可能的问题?

google-maps google-maps-api-3 angularjs

52
推荐指数
8
解决办法
11万
查看次数

GoogleMaps不会在页面加载时加载

我无法使用GoogleMaps API V3运行我的地图.地图无法加载.我希望地图显示在带有ID的div中,gisMap但在Chrome调试器中,我收到消息:

Uncaught InvalidValueError: initMap is not a function
Run Code Online (Sandbox Code Playgroud)

使用Javascript

var map;

function initMap() {
    // Enabling new cartography and themes
    google.maps.visualRefresh = true;

    // Setting starting options
    var mapOptions = {
        center: new google.maps.LatLng(39.9078, 32.8252),
        zoom: 10,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    // Getting Map DOM Element
    var mapElement = document.getElementById('gisMap');

    // Creating a map with DOM element
    map = new google.maps.Map(mapElement, mapOptions);
}
Run Code Online (Sandbox Code Playgroud)

Bundle.js(摘录)

(...)
module.exports = Vue;
}).call(this,require('_process'))
},{"_process":1}],3:[function(require,module,exports){
'use strict';

var map;

function initMap() { …
Run Code Online (Sandbox Code Playgroud)

html javascript google-maps

12
推荐指数
2
解决办法
5万
查看次数

如何在使用Browserify时公开Goog​​le地图的回调功能?

我正在使用Gulp和Browserify捆绑我的JavaScripts.我需要公开一个应该在加载Google Maps API后执行的回调函数.

如果不使用类似的东西window.initMap怎么办呢?这个问题是我需要在initMap中触发大量其他方法,因此除了使用window.functionName和污染全局命名空间之外,还必须有更好的方法.

另一方面,只是排除callback参数并做这样的事情是否可以?

$.getScript('https://maps.googleapis.com/maps/api/js').done(function() {
  initMap();
});
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.我花了更多的时间来承认让它发挥作用.

gulpfile.js:

gulp.task('browserify', ['eslint'], function() {
  return browserify('/src/js/main.js')
    .bundle()
    .pipe(source('main.js'))
    .pipe(buffer())
    .pipe(gulp.dest('/dist/js'))
    .pipe(reload({ stream: true }));
});
Run Code Online (Sandbox Code Playgroud)

main.js:

require('jquery');
require('./map');
Run Code Online (Sandbox Code Playgroud)

map.js:

var map = (function() {
  'use strict';

  var mapElement = $('#map');

  function googleMapsAPI() {
    $.getScript('https://maps.googleapis.com/maps/api/js?callback=initMap');
  }

  function initMap() {
    var theMap = new google.maps.Map(mapElement);
    // functions...
  }

  function init() {
    googleMapsAPI();
  }
});

map.init();
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-maps browserify gulp

7
推荐指数
1
解决办法
1798
查看次数

Uncaught InvalidValueError:initMap不是函数

我正在尝试加载带有一些特定参数的谷歌地图.我理解问题很可能是initMap函数需要全局声明.但是,即使在搜索了一些类似问题的StackOverflow帖子后,我也不知道如何.

其余的部分

 <script>
 var databaseArray = [{id: 'BTS1', arfcn: '70', bsic: '29'}
,{id: 'BTS2', arfcn: '60', bsic: '28'}
,{id: 'BTS3', arfcn: '65', bsic: '27'}
,{id: 'BTS4', arfcn: '55', bsic: '26'}
,{id: 'BTS5', arfcn: '75', bsic: '29'}];

var locationArray = [{lat: '60.78064', lng: '10.67037'}
,{lat: '60.76978', lng: '10.66677'}
,{lat: '60.76991', lng: '10.69672'}
,{lat: '60.78889', lng: '10.68462'}
,{lat: '60.76086', lng: '10.65141'}];


function displayDatabase(){
  var table1 = document.getElementById('database');
  for (var i = 0; i < databaseArray.length; i++){
      var bts = databaseArray[i];
      var row …
Run Code Online (Sandbox Code Playgroud)

javascript google-maps

6
推荐指数
2
解决办法
3万
查看次数

检查何时加载了异步javascript文件

我想在所有异步文件加载后"引导"我的页面.有没有办法在加载异步文件时收到通知?

的index.html

<script src="fileone.js" type="text/javascript" async></script>
<script src="filetwo.js" type="text/javascript" async></script>
<script src="bootstrap.js" type="text/javascript" async></script>
Run Code Online (Sandbox Code Playgroud)

html javascript html5 asynchronous

2
推荐指数
1
解决办法
2484
查看次数