2016-08-19 11 views
0

私はGoogle Maps APIで大きく動作する小さなプロジェクトに取り組んでいます。私はエラーはありませんが、マップがロードされるはずのページは空です。私はそれが私の場所オブジェクトが渡されているとプロパティは、オブジェクトが渡されている検査されていないためだと思う。キャッチコピーエラー:Google未定義| Google Maps API

あなたがゴーゴルマップapiについて知っていて、あなたが助けることができるなら、私は本当にそれを評価するでしょう。

/*----------------list of all the global variables---------------------*/ 
 
var map; 
 

 
/*----------------This is the model---------------------*/ 
 
var initialLocation = { 
 
    center:{ 
 
    lng: 33.895593, 
 
    lat: -117.316224 
 
    }, 
 
    zoom: 15 
 
} 
 

 
/*----------------This is the viewmodel---------------------*/ 
 
function initMap(){ 
 
    map = new google.maps.Map(document.getElementById("googleMap"), initialLocation); 
 
} 
 

 
/*----------------This is the view---------------------*/ 
 
$("googleMap").append(map);
html, 
 
.container{ 
 
    height: 100%; 
 
    width: 100%; 
 
    font-family: helvetica, sans-serif; 
 
    margin: 0px; 
 
    padding: 0px; 
 
    background-color: lightgrey; 
 
} 
 

 
#googleMap{ 
 
    height: 100%; 
 
}
<html> 
 
    <head> 
 
    <title>Omar Jandali Udacity Map</title> 
 
    </head> 
 
    <body> 
 
    <div id="container"> 
 

 
    </div> 
 
    <script type="text/javascript" src="collections/underscore.js"></script> 
 
    <script type="text/javascript" src="collections/backbone.js"></script> 
 
    <script type="text/javascript" src="collections/jquery-3.1.0.js"></script> 
 
    <script type="text/javascript" async defer 
 
     src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDik_TF3x4yc96CvWWw12YQ4DMjoG3vfFM&v=3&callback=initMap"></script> 
 
    <script type="text/javascript" src="js/main.js"></script> 
 
    </body> 
 
</html>

答えて

0

$("googleMap").append(map);実行、mapはまだnullに設定されます。 mapにマップオブジェクトが割り当てられた後に、コールバック関数initMap()内で実行する必要があります。

function initMap(){ 
    map = new google.maps.Map(document.getElementById("googleMap"), initialLocation); 
    $("#googleMap").append(map); 
} 
+0

を試してみてください、あなたのjQueryのセレクタは、IDを示すために ''#文字が欠落しています。 append(map) ' – Xoundboy

+0

私はそれを試みましたが、私はちょっと騒ぎましたが、まだ何もありませんでした。それは私が周りを混乱させたときにエラーなしで空白ですが、それはまだまたはエラーなしで何もロードされていません –

0

もこの

function initMap(){ 
var latlng = new google.maps.LatLng(-117.316224, 33.895593); 

var mapOptions = {zoom: 7, center:latlng} 

map = new google.maps.Map(document.getElementById("googleMap"), mapOptions); 

}