Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep Google Map static images on a fluid/responsive dimensions

I have been googling about it a lot, but couldn't find any appreciable opinion over the same,

I need to incorporate a static google map image in a jQuery Mobile project, for building an app with phonegap. The map image has to fill the viewport almost completely. Question is how, as it will obviously be opened across different devices of different screen sizes. I have tried with the percentage approach, but that certainly doesn't work here.

I would like to get some guidance on keeping the layout for the google map static image in a fluid layout, in the simplest possible way (Please, if possible).

Thanks

like image 609
Learner Always Avatar asked Nov 11 '13 10:11

Learner Always


People also ask

Is Google map dynamic or static?

Since the map produced is a static image, it won't be interactive or tailored to the user but it can be stylised through the custom parameters.

Is Google maps static API free?

Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).

What is the static of Google Maps?

The Maps Static API lets you embed a Google Maps image on your web page without requiring JavaScript or any dynamic page loading. The Maps Static API service creates your map based on URL parameters sent through a standard HTTP request and returns the map as an image you can display on your web page.


2 Answers

load the largest image size you are going to need initially into a container e.g. size of 380 x 250

this will be position:relative with overflow hidden and max size you need.

figre 
    {
        position:relative;
        width: 100%;
        overflow:hidden;
    }

then absolutely position the using top & left to position the image centrally inside the container.

e.g.

figure img
    {
        position: absolute;
        top: calc(50% - 125px);
        left: calc(50% - 190px);
        }
like image 108
user2292370 Avatar answered Nov 15 '22 21:11

user2292370


I have tried to style Google Static Map to follow the Bootstrap by referring to this website http://webdesigntutsplus.s3.amazonaws.com/tuts/365_google_maps/demo/index.html

index.html

<div class="col-sm-8 map-wrapper">
    <a target="_blank" class="map-container" href="LINK_TO_GOOGLE_MAP">
         <img src="YOUR_GOOGLE_STATIC_MAP_QUERY">
    </a>
</div>

css

a.map-container {
    display: block;
    background-image: url("YOUR_GOOGLE_STATIC_MAP_QUERY");
    background-repeat: no-repeat;
    background-position: 50% 50%;
    line-height: 0;
}
.map-container img
{
    max-width: 100%;
    opacity: 0;
}

The static map now is responsive on my website. I am not sure if it is applicable to you, but this is how I do it.

like image 20
Eddy Goh Avatar answered Nov 15 '22 21:11

Eddy Goh