2013-09-21 146 views
0

我正在嘗試使用Google Maps API。我直接複製從文檔the example code但地圖顯示不出來我預想的方式:Google地圖不顯示

enter image description here

我想看看通過我的代碼,看看是否有任何錯誤,但沒有運氣。任何想法?

http://jsfiddle.net/DerekL/B3KYB/(關鍵是去除)

function initialize() { 
    var mapOptions = { 
     zoom: 8, 
     center: new google.maps.LatLng(-34.397, 150.644), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    var map = new google.maps.Map($("#mapView")[0], mapOptions); 
} 
+0

嘗試'的document.getElementById( 'MapView的')',而不是使用jQuery。 – RobH

+0

@RobH - 我不是真的在我的代碼中返回一個jQuery對象。但我曾嘗試將其改爲本機方法,但問題仍然存在。 –

回答

4

你的CSS:

div, body, html { 
    width: 100%; 
    height: 100%; 
    margin: 0; 
    padding: 0; 
} 

...會影響網頁中的任何DIV元素,也由地圖的API創建的div的。

使用此選擇,而不是:#mapView, body, html

http://jsfiddle.net/doktormolle/nmwHw/

+0

+1很酷,我在小提琴中得到它。當我回來時,我看到了你的答案。我想補充一點,css應該像'#mapView {width = 100%;寬度= 100%; 身高:100%; margin:0; 填充:0; } ' – Praveen

+0

哦!不知道爲什麼我沒有抓住這一點,謝謝! –