我正在开发一个应用程序,其中包含google maps
。
script
如下。
<script>https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false</script>
<script>
$(function() {
var map;
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(13.004558, 77.6017),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.trigger(map, "resize");
});
</script>
而div
是
它没有正确调整大小,但是一旦你单击inspect元素就会调整大小。请帮我找出解决方案。工作更受赞赏
答案 0 :(得分:0)
在这一行
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
您不需要&#39; var&#39;
是否包括jquery?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
并尝试这种方式
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
答案 1 :(得分:0)
<script src ="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src ="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var map;
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(13.004558, 77.6017),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(
document.getElementById('map-canvas'),
mapOptions);
$("#map-canvas").css("height", "120px");
google.maps.event.trigger(map, "resize");
});
</script>
<div id = "map-canvas"></div>