TypeError:GMaps不是构造函数

时间:2012-10-22 21:09:53

标签: javascript jquery google-maps

我正在尝试使用gmaps.js在我的网站上显示Google地图。

<div id="map">
    <!-- GMaps.js injection here. -->
</div>

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        var map = new GMaps({
            div: '#map',
            lat: -12.043333,
            lng: -77.028333
        });
    });
</script>

我在Firebugs控制台上收到以下错误:

TypeError: GMaps is not a constructor
    lng: -77.028333

在我的_Layout.cshtml文件中,这里是对jQuery和其他Javascript库的引用:

<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js">
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js">
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/blitzer/jquery-ui.css" rel="Stylesheet">
<link rel="stylesheet" type="text/css" href="/cassette.axd/asset/Public/assets/stylesheets/main.less?zrfwD7IeGX87BD2hXeX_19D7PM4=">
<link rel="stylesheet" type="text/css" href="/cassette.axd/asset/Public/assets/stylesheets/bootstrap.css?Fr-zb2zZgNbHEFtP2LHSlWzPcTc=">
<script type="text/javascript" src="/cassette.axd/asset/Public/assets/javascripts/gmaps.js?l4YO_kYaJ82XSUboAjqvgNOTSog=">
<script type="text/javascript" src="/cassette.axd/asset/Public/assets/javascripts/jquery.unobtrusive-ajax.js?1e4_Y6C_dosNDw5vnP_HMJnJOaI=">
<script type="text/javascript" src="/cassette.axd/asset/Public/assets/javascripts/jquery.validate.js?N48SH-DQLi1ZxkCU5H4QfkU_Vqk=">
<script type="text/javascript" src="/cassette.axd/asset/Public/assets/javascripts/jquery.validate.unobtrusive.js?H9QpwLXle-pJHFboqVks8SmWPD8=">
<script type="text/javascript" src="/cassette.axd/asset/Public/assets/javascripts/MicrosoftAjax.debug.js?5os4UsHTQvdRWuk_dD_ZJbhKv2o=">
<script type="text/javascript" src="/cassette.axd/asset/Public/assets/javascripts/MicrosoftMvcAjax.debug.js?VuXJYhbnFpRWN4gr3pwlAyCdWUg=">
<script type="text/javascript" src="/cassette.axd/asset/Public/assets/javascripts/MicrosoftMvcValidation.debug.js?HcBKh9uDD_B8LpYqpQW1dYU6woI=">
</head>

为什么会被解雇的任何想法?

1 个答案:

答案 0 :(得分:2)

你错过了

 <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
从标题中

。如果你看一下gmaps.js的第一行,你会看到

if(window.google && window.google.maps){

因此,它依赖于Google Maps API,即使它简化了它。