1

我尝试连接 RequireJS 和谷歌地图。我有这个代码

    require(['gmapapi'], function(google){
    var map;

      var mapOptions = {
        zoom: 8,
        center: new google.LatLng(-34.397, 150.644),
        mapTypeId: google.MapTypeId.ROADMAP
      };
      map = new google.Map(document.getElementById('map'),
          {});

});

在需要配置中gmapapi: '//maps.googleapis.com/maps/api/js?sensor=false',

但我收到错误Cannot read property 'LatLng' of undefined如何访问此对象?

4

1 回答 1

0

我使用异步插件解决了这个问题。在路径中添加

async:'//raw.github.com/millermedeiros/requirejs-plugins/master/src/async',

在 JavaScript 文件中:

require(['async!//maps.googleapis.com/maps/api/js?sensor=true'], function(){
var mapDiv = document.getElementById('map');

      var map = new google.maps.Map(mapDiv, {
        center: new google.maps.LatLng(37.4419, -122.1419),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        navigationControl: true,
        navigationControlOptions: {
          style: google.maps.NavigationControlStyle.SMALL
        }
});
于 2013-08-10T14:39:04.433 回答