Utilizing Google Maps within a responsive layout with 2 columns

Seeking guidance on integrating a map into the second column of a responsive website. Acknowledging that my code may not be optimal, as this is my first attempt at such a task. After a day of searching for solutions, I'm feeling quite desperate.

HTML

<div class="section group">
<div class="col span_1_of_2">
</div>
<div class="col span_1_of_2">
    <div id="map-canvas"></div>
</div>
</div>

CSS

.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }

.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
.span_2_of_2 {
width: 100%;
}
.span_1_of_2 {
width: 49.2%;
}
#map-canvas {
    height: 100%;
    width: 100%;
    }

@media only screen and (max-width: 480px) {
.col { 
    margin: 1% 0 1% 0%;
}
}

@media only screen and (max-width: 480px) {
.span_2_of_2, .span_1_of_2, #map-canvas { width: 100%; }
}

Javascript code can be found in the following links:

http://codepen.io/anon/pen/doZBGb If the CodePen link is not functional: https://gist.github.com/anonymous/161951ccd66d110aed83

Any assistance or suggestions are greatly appreciated.

Answer №1

Well now...

JSfiddle Example.

let map;
let coordinates;

function addMarker(location) {
    //marker will only be visible within this function
    let marker = new google.maps.Marker({
        position: location,
        map: map,
        draggable: true
    });
}

function initMap() {

    let centralPosition = new google.maps.LatLng(46.910246, 18.048979);
    let options = {
        zoom: 6,
        center: centralPosition,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map($('#map')[0], options);

    google.maps.event.addListener(map, 'click', function (evt) {
        addMarker(evt.latLng);
        coordinates = Array(evt.latLng + ';');
    });

}

$(document).ready(function() {
    initMap();

    $('input[name="get-coordinates"]').click(function() {
        console.log(coordinates);
    });
});

and it's as simple as:

#map { // use this selector for responsive design
    width: 450px; // adjust this to %
    height: 400px; // or apply @media queries 
}

...that's all there is to it!

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

Tips for disabling automatic sliding in Bootstrap 5 carousel specifically on larger screens

I am working with a Bootstrap 5 carousel that I need to configure to stop autosliding on large screens, but maintain autoslide functionality on mobile devices. Is there a way to achieve this using only HTML and CSS/SCSS? I am aware of the data-bs-interval ...

What is the best way to set a specific image as the initial image when loading 'SpriteSpin'?

I'm currently working on creating a 360-degree view using the SpriteSpin API. Everything is functioning as expected, but I have an additional request. I need to specify a specific image to be the initial landing image when the page loads. The landing ...

Is it possible for a font to exclude the space character?

I'm currently developing a font detection library that must be extremely compact in size, perfect for direct inclusion on every page of a website. I've managed to shrink it down quite a bit already (compressed to 417 bytes). Take a look at it on ...

Missing ng-required fields not displaying the has-error validation in AngularJS forms

While editing any part of their address, the user should see a red invalid border around each field to indicate that the full form is required. However, for some reason I can't seem to get the 'Address' field to display this border. The set ...

Personalized Grid Design for Showcasing Athletic Teams

I am looking to create a custom grid layout that represents the team's Players, separated by their positions (GK, Defense, Midfielders, and Forwards), similar to the image below. The layout should also be responsive like in image 1. Currently, the re ...

What is the best way to conceal a canvas or another item?

Within my main canvas, there are three smaller canvases and a text element. <canvas id="Background" width="350" height="300" style="border:6px solid black; position: absolute; left: 10px; top: 10px;"> </canvas> <canvas id="Canvas1" width ...

The image does not properly scale within the div as it rotates

I am currently attempting to use jQuery to rotate an image, but I am facing an issue. When I rotate the image left or right, a portion of it extends beyond the frame. The image is not resizing based on the CSS properties set as max-height: 100%; max-width: ...

Add a fading transition feature to images that are loaded at a later time

I used a clever technique to create a blur effect by loading a small, lightweight image first. Once the main background image is loaded, it swaps out the 'data-src' with the actual image. However, I am facing an issue with the abrupt transition, ...

What are some ways to create a one-sided design without being limited by container constraints

How can I create a block on my site where there are no container restrictions on the right, but they are limited on the left? The goal is to have an image pressed against the right edge of the page while keeping the container limits on the left. Here is my ...

Eliminate any empty spaces and gaps present between div elements

Is there a way to eliminate the spaces between div containers at the bottom part of the div with a red border? The following code snippets utilize materializecss. /*############################ LOGIN STYLE ############################*/ body{ font: ...

Is it possible to reorganize the order of elements in a

My goal is to create a flex column layout where the image appears first. However, I'm facing an issue with the code below, as it only changes the order when the flex direction is set to row (image on the left). It does not work for rows. </head> ...

Achieving a layered effect with elements overlapping onto another div

Looking for a way to create a design where the text in id="text-field" overlaps with id="image-field". Need some guidance on how to achieve this effect. Any help is appreciated. <!DOCTYPE html> <html> <body> <div class=" ...

Having troubles with angular due to doodle throwing errors?

https://codepen.io/tuckermassad/pen/rPYNLq I took the CSS doodle code from the above link and incorporated it into my angular component: <section class="main"> <css-doodle grid="5"> :doodle { @grid: 10 / 100%; } ...

Strategies for addressing input range slider cross browser compatibility issues

I have encountered an issue with the slider track while using a customized range slider with CSS. For Mozilla, I utilized the selector for progress (-moz-range-progress) and for IE I used -ms-filler-lower and -ms-filler-upper. Although it works well for b ...

Position the SVG next to the link text in a Bootstrap navbar brand

I am using the .navbar-brand class from Bootstrap to include an SVG in my navbar. However, I want to display text next to the SVG and align it properly. The SVG and text are currently in the navbar but they are not aligned correctly. Below is the code snip ...

Steps for accessing CSS variables within a scoped style block in Vue with Buefy_integration

After diving into the Buefy documentation, I successfully personalized my color scheme and even crafted unique hues by applying the is-[colorName] as a class to HTML elements. <style lang="scss"> // Importing Bulma's core @import "~bulm ...

Enhancing Image Quality in JavaFx's Scene Builder

Hey everyone! I've been using JavaFx scene builder to create a user interface with some png images. Up to now, I've been using labels and enlarging them to display the pictures, but this solution isn't ideal because I need to create multipl ...

Is it common for content to duplicate when using the 'position: fixed' property in CSS media print?

Consider the following div element: ... <div id='section-to-print'>CONT /*Content*/ </div> ... Accompanied by this CSS code snippet: @media print { * { -webkit-transition: none !important; ...

Achieving fixed width and automatic height for images in Next JS: a guide

I am struggling to showcase a list of images with a fixed width while utilizing the original image height set at 100%. A similar inquiry can be found here, yet it remains unanswered. I have gone through the responses shared here and attempted them. The im ...

problem when trying to establish the minimum height for a div element prior to the website being fully loaded, considering the

Having trouble with a CSS issue that seems simple but I can't find a solution for. I have a main div with a min-height set to a certain value, specified in %. Since there is no outer div, the min-height won't display if it's given in px. I ...