我已經創建了一個地圖到邊框。當我用圖片填充框架時,它完全填充整個框架,但是當我在框架中插入地圖時,它會在框架和地圖的邊框之間留下一個小間隙。我試圖改變地圖高度,但它沒有幫助。我有兩個問題:地圖和邊框之間的差距
- 爲什麼代碼的行爲如此?
- 如何正確填寫地圖 整個框架?
圖片:
代碼:
<script type="text/javascript">
//<![CDATA[
var customIcons = {
restaurant: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png'
},
bar: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(47.6145, -122.3418),
zoom: 13,
mapTypeId: 'roadmap'
//google.maps.event.trigger(map, 'resize');
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
</script>
map.css
#map {width: 100%;height: 98vh;margin: 0px;padding: 0px;}
的示例我們可以至少看到代碼嗎? – 2015-03-18 20:55:40
您可能想要顯示您的CSS/HTML代碼。您可能會在地圖視圖的頂部設置一些邊距。 – ztan 2015-03-19 16:12:39
@ztan通過添加CSS代碼更新了問題,但在HTML中實際上應該沒有任何問題。 – AndroidProgrammer 2015-03-19 17:39:48