【问题标题】:Ionic 3 google maps height proportional to screen sizeIonic 3 谷歌地图高度与屏幕尺寸成正比
【发布时间】:2018-06-07 15:45:52
【问题描述】:

我正在尝试让更高的谷歌地图填满屏幕的整个高度(无论手机的大小)加上最底部的固定高度按钮。我正在使用Ionic 3

现在在iPhone 5 上看起来很完美,而在iPhone X(更大的屏幕)上,地图太大了。 iPhone 6 就在中间(不好)。

<ion-content no-bounce>
  <div class="container">
    <ion-list class="autocomplete-list">
      <ion-item class="autocomplete-class" type="text" placeholder="Pick an address">{{this.geocoding.locationObject}}</ion-item>
    </ion-list>
    <div #map id="map"></div>
  </div>
  <div class="buttonContainerSafeArea">
    <button (click)="next()" class="addLocationButton">Next</button>
  </div>
</ion-content>

我的 CSS 是:

.container {
    margin-bottom: constant(safe-area-inset-bottom);
    margin-bottom: env(safe-area-inset-bottom);
    background-color: black;
    display: block;
    widows: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
  }
  #map {
    margin-bottom: constant(safe-area-inset-bottom);
    margin-bottom: env(safe-area-inset-bottom);
    position: fixed;
    top: 11%;
    width: 100%;
    height: 74.9%;
    z-index: 99;
    padding: 0;
    margin: 0;
  }
  .addLocationButton {
    position: absolute;
    bottom: 0;
    z-index : 999;
    width: 100%;
    height: 45px;
    margin: 0;
    text-align: center;
    vertical-align: middle;
    font-size: 15px;
    font-family: $font-family-buttons;
    font-weight: 500;
    color: #ffffff;
    background-color: $red-color;
    opacity: 0.9;
  }
  .buttonContainerSafeArea {
    margin-bottom: constant(safe-area-inset-bottom);
    margin-bottom: env(safe-area-inset-bottom);
  }

【问题讨论】:

    标签: css google-maps ionic-framework ionic3


    【解决方案1】:

    您可以尝试使用此代码获取全高谷歌地图。

    ts

    height : string;
    constructor(public navCtrl: NavController,public alertCtrl:AlertController) 
    {
        this.height = (document.documentElement.clientHeight-15)+"px";
    }
    

    html

    <ion-content>
        <div #map id="map" [style.width]="'100%'" [style.height]="height"></div>
        <div class="buttonContainerSafeArea">
            <button (click)="next()" class="addLocationButton">Next</button>
        </div>
    </ion-content>
    

    document.documentElement.clientHeight 你必须减去按钮高度。如果您在顶部添加更多元素,则还必须减去这些元素的高度。

    【讨论】:

    • 谢谢,部分工作,只是现在我需要从这个值中减去导航栏、选项卡和输入字段,它们对于不同的 iphone 尺寸是不同的。知道如何获得这些尺寸吗?谢谢!
    • 我认为你必须手动调整它并减去它。我认为所有设备的尺寸都一样
    • 我不认为这是相同的,因为使用相同的“减号”值会给出从 iPhone 5 到 iPhone 7plus 的非常不同的尺寸。
    • 您的方法有效。知道如何在 HTML 代码中表示它:“#map:after {margin: 20px}”。 [style.margin-top]="topDisplacement" 可能会影响整个#map。
    • 意味着你必须从顶部留出边距?
    猜你喜欢
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多