gpt4 book ai didi

javascript - 我的 map 在 jsfiddle 中有效,但在浏览器中无效

转载 作者:行者123 更新时间:2023-11-28 03:59:52 26 4
gpt4 key购买 nike

这是工作的 jsfiddle:http://jsfiddle.net/LzezLgtz/74/

<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<style>
#map-canvas {
height: 400px;
width: 100%;
margin: 0px;
padding: 0px
}
.controls {
margin-top: 10px;
border: 1px solid transparent;
border-radius: 2px 0 0 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
height: 32px;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#pac-input {
background-color: #fff;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
margin-left: 12px;
padding: 0 11px 0 13px;
text-overflow: ellipsis;
width: 300px;
}
#pac-input:focus {
border-color: #4d90fe;
}
.pac-container {
font-family: Roboto;
}
#type-selector {
color: #fff;
background-color: #4d90fe;
padding: 5px 11px 0px 11px;
}
#type-selector label {
font-family: Roboto;
font-size: 13px;
font-weight: 300;
}
#target {
width: 345px;
}
</style>
</head>

<body>
<div id="map-canvas" style="border: 2px solid #3872ac;"></div>
<input id="pac-input" class="controls" type="text" placeholder="Search Box">
<script>



function initialize() {


var myLatlng = new google.maps.LatLng(12.112, -86.2907);

var myOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new google.maps.Map(document.getElementById('map-canvas'), myOptions);

// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});

var markers = [];
// [START region_getplaces]
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();

if (places.length == 0) {
return;
}

// Clear out the old markers.
markers.forEach(function(marker) {
marker.setMap(null);
});
markers = [];

// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};

// Create a marker for each place.
google.maps.event.addListener(map, 'click', function(event) {

alert(event.latLng);
});

if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}

});
map.fitBounds(bounds);

});

}

google.maps.event.addDomListener(window, 'load', initialize);

</script>
</body>
</html>

这是不起作用的 html:https://www.cootel.com.ni/cootel/wp-content/files/mapas/mapa-nicaragua.html

我已经在我的本地计算机上试过了,我得到了同样的结果。它仅适用于 jsfiddle。

任何帮助将不胜感激。谢谢!

最佳答案

改变你的CSS从

#map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}

html, body, #map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}

在您的 html 页面中。

关于javascript - 我的 map 在 jsfiddle 中有效,但在浏览器中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43267682/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com