html - 谷歌地图 API 未以全尺寸显示

标签 html google-maps jquery-mobile

我将 jQuery Mobile 用于我的 iOS 应用程序。这是我加载 map 时内部发生的情况:

enter image description here

为了生成它,我使用了以下脚本。

var map
var mark

function initialize() {
    var latlng = new google.maps.LatLng(52.404657,-1.491413);
    var myOptions = {
    zoom: 13,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"),
                              myOptions);


    mark = new google.maps.Marker( {
                                      position: latlng,
                                      map:map   
                                      })
}

function mostrarUbicacion(){
    navigator.geolocation.getCurrentPosition( lecturaGPS , errorGPS , {enableHighAccuracy:true} )  
}

function lecturaGPS(ubicacion){

    var miubicacion = new google.maps.LatLng(ubicacion.coords.latitude, ubicacion.coords.longitude);

    map.setCenter(miubicacion)
    mark.setPosition(miubicacion)

}

function errorGPS(){
    alerta(" unable to connect")
}

html:

<body onload="initialize()" style="height:100%">
<div id="map_canvas" style="width:100%; height:50%; padding:0;"></div>
<button onClick="mostrarUbicacion()"> Click to find where you are! </button>
</body>

最佳答案

尝试以这种方式设置 map 和 css 的 div:

HTML:

<div class="Flexible-container" id="map" style="margin:1.5%;">
    <!-- this is the div for the map -->
</div>

CSS:

/* Flexible iFrame */

.Flexible-container {
    position: relative;
    padding-bottom: 32.25%;
    padding-top: 30px;
    height: 0;
    overflow: hidden;
}

.Flexible-container iframe,   
.Flexible-container object,  
.Flexible-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

要调整 div 的宽度,请使用百分比;您可以调整高度设置 padding-bottom

here the doc

关于html - 谷歌地图 API 未以全尺寸显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10437919/

相关文章:

asp.net-mvc - jQuery Mobile 1.3.x 和 ASP.NET MVC 4 Razor 的 ListView 渲染问题

html - 如何使一行图像居中?

javascript - 使用 .getElementsByClassName 将 <string> 标签替换为 <br/> 标签

javascript - 使用自定义创建的 Mapbox 样式(来自 Mapbox Studio)和 Leaflet

java - 在世界地图上显示位置

javascript - 调整圆大小时获取半径

css - 为具有静态页脚的页面设置 jquery 移动最小页面高度

iphone - 平板电脑/移动设备上的数字内容被删除/隐藏

java - 在 Google map Activity 中的特定位置显示消息?

php - 将 php 中的日期时间值填充到 Jquery Moble 文本输入 datetime-local 中