第一次使用谷歌地图API,地图没有出现。我读过很多关于引起问题的高度和宽度声明的内容,我尝试用所有相关的样式从%切换到px,没有做任何更改。
我正在rails 4.2.1中工作
映射Javascript最初是引导模板的一部分
这是我的Javascript
function init() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(40.6700, -73.9400), // New York
// Disables the default Google Maps UI components
disableDefaultUI: true,
scrollwheel: false,
draggable: false,
// How you would like to style the map.
styles: [{
"featureType": "road",
"elementType": "geometry",
"stylers": [
{
"lightness": 100
},
{
"visibility": "simplified"
}
]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [
{
"visibility": "on"
},
{
"color": "#C6E2FF"
}
]
},
{
"featureType": "poi",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#C5E3BF"
}
]
},
{
"featureType": "road",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#D1D1B8"
}]
}]
};
// When the window has finished loading create our google map below
google.maps.event.addDomListener(window, 'load', init);
// Get the HTML DOM element that will contain your map
var mapElement = document.getElementById('map');
// Create the Google Map using our element and options defined above
var map = new google.maps.Map(mapElement, mapOptions);在index.html.erb中,
地图应该显示的区域:
<div id="map"></div>要链接到API的脚本标记:
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=my_api_key_here">
</script>在我的.less文件中关联的样式:
#map {
width: 100%;
height: 200px;
margin-top: 100px;
}
@media(min-width:767px) {
#map {
height: 400px;
margin-top: 250px;
}
}在我的.css文件中关联的样式:
#map {
width: 100%;
height: 200px;
margin-top: 100px;
}
@media(min-width:767px) {
#map {
height: 400px;
margin-top: 250px;
}
}任何建议都将不胜感激,谢谢!
发布于 2015-07-12 02:43:24
我找到了解决这个问题的答案。
我将callback=initialize选项添加到html中的脚本标记中:
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize"></script>这一职位有助于:
https://stackoverflow.com/questions/31363394
复制相似问题