我正在嘗試將帶有標記的谷歌地圖添加到我的表單中以幫助用戶選擇位置,但它出錯了。將谷歌地圖添加到頁面時出錯
正如你看到的,地圖上沒有正確地在其區域中顯示。我在地圖上放置了一個標記,並在那裏設置了中心,但該標記的位置不正確,它隱藏在初始地圖之外(位於上圖中的右上角,而不是中間)。
當我擊中F12按鈕啓用螢火蟲(在Firefox),地圖顯示正確
下面是創建的形式和添加谷歌地圖的代碼:
index.html中的形式文件:
<div id="map_company" style="float: left; width: 500px;height: 350px;">
<label style="margin-bottom: 5px;">Chọn vị trí hãng xe trên bản đồ:</label>
<div id="map_canvas" style="width: 100%; height: 100%; position: relative;"></div>
</div>
而且在腳本文件的JavaScript:
//add map to company tab
//Set Center
var myOptions =
{
center: new google.maps.LatLng(21.044813, 105.79864),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
}
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var comMarker = new google.maps.Marker({
position: new google.maps.LatLng(21.044813, 105.79864),
map: map,
draggable: true
});
google.maps.event.addListener(comMarker, 'dragend', function {
document.getElementById("cLat").value = this.getPosition().lat();
document.getElementById("cLon").value = this.getPosition().lng();
});
任何人都可以幫助我找出問題在這裏,我甚至不知道如何解釋它到谷歌。