Adjusting the height of Google Maps in Ionic 3 based on the screen size

To ensure that the Google Maps occupies the full height of the screen on all devices, regardless of size, including a fixed-height button at the bottom, I am utilizing Ionic 3.

Currently, the layout appears perfect on an iPhone 5, but on an iPhone X with a larger screen, the map is excessively large. The display on an iPhone 6 falls somewhere in between, not quite satisfactory.

<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>

The CSS code used is as follows:

.container {
    margin-bottom: constant(safe-area-inset-bottom);
    margin-bottom: env(safe-area-inset-bottom);
    background-color: black;
    display: block;
    width: 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);
  }

Answer №1

If you want a full height google map, you can use the following code snippet.

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>

To calculate the height for the Google map, subtract the button height from

document.documentElement.clientHeight
. If you have additional elements at the top, remember to also account for their heights.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When viewed on mobile devices, the image shrinks significantly

I'm experiencing an issue where the image shrinks significantly when viewed on a mobile device or when zooming in the browser. Can you help me understand why this is happening and suggest a solution? Here are the HTML and CSS code snippets: HTML < ...

Placing a moveable object in a designated spot for dropping at the desired location

I've been attempting to clone and drop a draggable object at the exact position within a droppable area where the drop event takes place. While I have come across examples online that demonstrate appending draggables to droppables, they all tend to re ...

Jumbotron text alignment in Bootstrap 3

I created a webpage using Bootstrap 3 that looks perfect on a computer screen. However, when viewed on a mobile screen, the text in the jumbotron is overflowing, causing a horizontal scroll bar to appear. <div id="home"> <div id="jumb" clas ...

Responsive tables in Bootstrap 4 that are nested

I am currently utilizing Bootstrap 4. I have a complex table structure where I want only the second column and onward to be scrollable. The challenge is making this specific part of the table responsive while keeping the rest static. I attempted to nest a ...

Is there a way to position an X item on the first row and another X item on the following row using flexbox?

I want to use flexbox to arrange 10 buttons in a row on a large screen. On a medium screen, I'd like 5 buttons on the first row and 5 on the second row. For small screens, 2 buttons per row, and for very small screens, one button per row. It's im ...

simply creating a simple Ionic project with the Cordova WKWebview Engine plugin can result in a blank white

Issue at Hand: I am facing a major slowdown in my ionic app development, which I have traced back to the UIWebView component. In search of a solution to enhance the speed, I have turned to using WKWebView as it seems to hold promise for improvement. Curre ...

How do I incorporate scrolling into Material-UI Tabs?

I am currently incorporating Material-ui Tablist into my AppBar component. However, I am facing an issue with the responsiveness of the tabs. When there are too many tabs, some of them become hidden on smaller screens. For more information on the componen ...

Position the text alongside the Facebook emblem

I am having trouble getting the text Follow Us to align on the far right next to the Facebook Icon. I added the float:right property, but it is not working as expected. Here is the code snippet: <a href="#" target="_blank" style="font-family: Arial, ...

The CSS import for fonts is causing no change in the font appearance

Hello there, I've just begun working on some CSS projects and I'm facing an issue with my font import. Despite writing the code below for the font import, I'm not seeing any change in the font: @font-face { font-family:gamefont; src:url(raw ...

Tips for aligning images and a slider perfectly in a single row

I am attempting to align 3 buttons in the center and a slider on the right side of the same line. However, I am facing an issue where when I center the buttons and float the slider to the right, the buttons lose their alignment in the middle. Here is how i ...

Angular is not properly integrating Bootstrap features

I've been attempting to create bootstrap accordion items, but unfortunately they're not functioning correctly as shown in the Bootstrap documentation or YouTube tutorials. In my angular.json file, I have included both bootstrap and jQuery for te ...

The widths of inputs vary between FireFox and Chrome

I've been investigating why the widths in FireFox and Chrome show a significant difference. This variation is causing a problem with my Modal in the views. Chrome: https://i.sstatic.net/D0lgu.png FireFox: https://i.sstatic.net/do4YU.png Upon comp ...

The Art of GSAP: Creating Seamless Performance and Structural Integrity

GSAP boasts about its ability to create stunning animations for the web using HTML5, but it's important to note that they specifically mention on Greensock.com that they do not rely on the canvas framework in HTML5. Although their code includes JavaSc ...

At what precise moment does React apply the CSS to a component?

In my app.js file, I import someComponent.js. This someComponent.js file then imports someStyles.css. However, app.js will only use or render someComponent.js when a button is clicked. So, the question arises: When will the user's browser load and ap ...

What is the best way to include a scrollbar in a modal window?

Does anyone know how to add a scroll function to my modal in CSS? I have too many elements and would like to implement a scrollbar. You can see what it looks like here: https://i.sstatic.net/4Txrn.png Any suggestions on how to add the right scrollbar? If ...

Navigating through the vertical and horizontal overflow of an image

When I hover over an image, it scales and the excess part of the image is hidden. However, I want the image to scale from the center by using transform-origin: 50% 50%. The issue arises when I try to scroll or drag around the transformed image - I can&apo ...

Can a fully operational "contact us" page be created with just HTML and CSS?

Is it feasible to create a "contact us" page that operates properly using only HTML/CSS? For instance, allowing a user to visit the "contact" page and input their email address and message, which would then be sent directly to my email. Would this be ach ...

What could be causing SimpLESS to throw a syntax error when encountering a forward-slash symbol in the background shorthand?

Can anyone explain why this specific line (line:2) is causing a syntax error on the SimpLESS compiler? When compiling in-browser using CDNs, there are no issues. However, the same code doesn't seem to work correctly on an iPad for some unknown reasons ...

Steps to Implement CSS Background Change on Click Event

Take a look at this JSFiddle link. In the code, you will find two divs called step-wrapper, each containing three divs named step-box. When you click on a step-box, its background color changes to yellow. I have included a reset button. What I want is for ...

Tips for adapting CSS images on mobile devices without distorting the aspect ratio

Our website is not responsive, and one of the requirements is to ensure that images render properly on mobile devices to fit the screen. However, we are encountering an issue due to the varying sizes of images uploaded to the web page. Below is the CSS co ...