Anyone with any ideas on what's causing this weird glitch with the google maps UI components, be really grateful to hear from you!
the map is created with:
var options = {
zoom: <?php echo $this->zoom ?>,
center: new google.maps.LatLng(<?php echo $this->centre_lat ?>, <?php echo $this->centre_lon ?>),
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'), options);
and the glitch is the same even with no markers.
We ran into the same problem. The css designer was using this style:
style.css
img {max-width: 100%; }
Instead of disabling the zoom control, we fixed the problem by overriding the img style for map_canvas elements like so:
style.css:
#map_canvas img { max-width: none; }
The zoom control now displays correctly.
Setting "img max-width:100%" is a technique employed in responsive/fluid web site design so that images re-size proportionally when the browser is re-sized. Apparently some css grid systems have started setting this style by default. More info about fluid images here: http://www.alistapart.com/articles/fluid-images/ Not sure why this conflicts with the google map...
With latest version of google maps api you need this:
<style>
.gm-style img { max-width: none; }
.gm-style label { width: auto; display: inline; }
</style>
Looks like a problem with the zoom control. Try adding zoomControl:false to your options.
In fact it seems the normal zoom slider is positioned off to the left of the page (use Firebug > Inspect Element). Could be a CSS conflict?
Well I got the fix for this:
On your CSS you added something like:
img {max-width: 100%; height: auto;}
try not to make it global and it should fix you :)
This worked for me:
#map img { max-width: none !important; } (from Patrick's answer)
the attribute "!important" makes sure to override any other style, #map is the id assigned when you declare the new object Gmaps:
<script>
map = new GMaps({
div: '#map', <- your id
lat: *******,
lng: *******,
scrollwheel: false,
panControl: true,
....
...
</script>
if you are using the Dreamweaver fluid grid feature your default set up should look like this:
img, object, embed, video {
max-width: 100%;
}
/* IE 6 does not support max-width so default to width 100% */
.ie6 img {
width:100%;
}
Try this:
object, embed, video {
max-width: 100%;
}
#map_canvas img { max-width: none; }
/* IE 6 does not support max-width so default to width 100% */
.ie6 img {
width:100%;
}
just replace the code as it is.
Bootstrap (as of version 2.3.2) messes with images in the same way as in the accepted answer.
In fact, I suspect that the design used in Haroldo's website uses Bootstrap.
I'm just posting this because no one else mentioned Bootstrap, and someone might be looking for a Bootstrap-specific solution.
I ran into this problem on my Square Space website. I did not have access to the CSS style sheet. Since you are embedding an html doc, you can just use inline CSS to fix the problem. I modified the style of the container instead of making a site wide change (which I couldn't do). Here is what I did:
<style>
html, body, #map-canvas {
height: 600px;
width: 100%;
margin: 0px;
padding: 0px
}
#map-canvas img {max-width: none;}
</style>
Related
UPDATED!
I am building a simple site modifying a free template with given style. I put a google map on the page and it behaves strange. In internet explorer it works just fine. In chrome it fails to work after the page is loaded (it is fully grey with google sign), but I realized that it works fine after I zoom in or out the browser. What can cause this problem? I was searching for answer for some days, but could not find any reasonable solution for my problem.
I have a simple div in HTML for the place of the map, the article is opened form the main page using the same link with id (index.html#contact).
The height and width of the map's div is given!
I put the lines for resizing that gave solution for many others, but me.
I am totally fed up with this issue spending days and days just trying to figure out the f***ing soultion without any result.
<article id="contact">
...
<div id="map"></div>
...
</article>
The script looks like this (I removed my key and put mykey instead, do not mention that pls.):
<script>
function myMap() {
var myLatlng = new google.maps.LatLng(-13.163138, -72.545053);
var mapOptions = {
center: myLatlng,
zoom: 14,
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
google.maps.event.addListenerOnce(map, 'idle', function() {
google.maps.event.trigger(map, 'resize');
map.setCenter(latLng);
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=mykey&callback=myMap"></script>
The css code for the map: (maybe some other parts of then css has effect on it as well, not sure...)
#map {
width: 400px;
height: 400px;
background-color: grey;
overflow:visible;
margin: auto;
}
#map img {
max-width: none !important;
}
#media screen and (max-width: 480px) {
#map {
width: 200px;
height: 200px;
background-color: grey;
overflow:visible;
margin: auto;
}
#map img {
max-width: 200px;
}
}
For some reason InfoWindow is displaying scroll bars along with the content, I tried to have custom width and height to InfoWindow but it is not showing up.
I tried the solution from here
Google Map Infowindow not showing properly
Please refer following link
http://server.ashoresystems.com/~contacth/index.php?option=com_business&view=categoryresult&catid=2
Click on 1 (has scroll bars)
Click on 3 (even disturbed)
Thanks for any help.
I found a workaround here.
I made this JSfiddle, displaying the bug and a workaround.
If you do not want to visit external links, here is the workaround description:
Add a wrapping div to your info window content:
var infoWindow = new google.maps.InfoWindow({
content: '<div class="scrollFix">'+infoWindowContent+'</div>',
[...]
}).open(map);
And use CSS definitions to avoid scrollbars:
.scrollFix {
line-height: 1.35;
overflow: hidden;
white-space: nowrap;
}
To hide the scrollbars, give your content a high z-index stack order, eg.:
var infowindow = new google.maps.InfoWindow({
content: '<div style="z-index:99999">Message appears here</div>',
});
Or, add the following style:
.gm-style-iw {
overflow:hidden!important;
height:55px!important; //for 3 lines of text in the InfoWindow
}
Google maps adds style="overflow: auto;" to the content root element and removes all other attributes, including your style=... or class="scrollFix". You can override overflow: autolike this:
.gm-style-iw div * {
overflow: hidden !important;
line-height: 1.35em;
}
I have an extension that changes the appearance of my scrollbars. That is why the ugly scrollbars appear on Google API info window boxes.
To get rid of the scrollbars and to have a good amount of padding, I just appended the following to my scrollbar appearance code:
div.gm-style-iw.gm-style-iw-c {
padding-right: 12px !important;
padding-bottom: 12px !important;
}
div.gm-style-iw.gm-style-iw-c div.gm-style-iw-d {
overflow: unset !important;
}
You could probably just add that to your site too, to make it a fix for all your users.
I am writing a jquery mobile app which needs a map.
For the map I am planning to use Google maps service.
To account for orientation changes, I tried to use something like:
<script>
$('#page-map').live('pagecreate', function(event) {
var map = $('#map_canvas').gmap({
...
});
...
$(window).resize(function() {
$('#map_canvas').width($(window).width());
$('#map_canvas').height($(window).height());
});
)};
</script>
The problem: this code correctly resizes the map canvas when the device is rotated, but it looks like jquery mobile resize() is skipped (the url bar is visible, for example...).
Not even adding to the "resize(function() {" code something like this:
google.maps.event.trigger(map, 'resize');
is of any help.
UPDATE:
The issue only happens on the only mobile device I'm testing my pages - a Samsung Galaxy Mini (GT-S5570), Android 2.3.4 (Gingerbread). It does not happen when resizing window on a desktop PC (i.e: on a desktop browser map_canvas is correctly filled when browser's window is enlarged, even without the resize() binding, only due to width/height at 100% on map_canvas...)
I assign a size through css to my map in jquery mobile
I add the map_canvas inside div with dimencion deuin want in this case 100%
CSS
#map_content {
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;}
#map_canvas {
width: 100%;
height: 100%;
padding: 0;
text-shadow: none;}
HTML
<div data-role="content" id="map_content" data-theme="a">
<div id="map_content">
<div id="map_canvas"></div>
</div>
</div>
I've tried the above answer (plus many others) and nothing worked for me. Actually, the above code was working for me, but just until I started using jQuery Mobile. Somehow, when I load jQuery Mobile (funnily enough, I noticed that it's the JS, no the CSS) the map_canvas has no height (a trick to check the height of the element is adding a border to it like border: 1px solid red;).
Eventually, I managed to solve the auto-resize when the orientation changes by using the following code/css:
<div data-role="page" id="pageID">
<div role="main" class="ui-content">
<div id="map_canvas">
</div>
</div>
</div>
And in the css:
html,
body,
#pageID {
height: 100%;
margin: 0;
padding: 0;
}
.ui-content {
padding: 0;
}
.ui-content,
.ui-content #map_canvas {
height: inherit; /* the trick */
}
So, basically the: height: inherit; solved the problem for me.
Credits: https://jqmtricks.wordpress.com/2014/12/01/content-div-height-css-solution/comment-page-1/#comment-250
I hope it helps!
I have an app built on Cordova and on some of my pages I am able to scroll horizontally out of my content into white space.
This is weird as I have nothing there that extends beyond my #wrapper, which is set to width: 100%.
So I was wondering if there was a way I could disable horizontal scrolling in the app altogether?
UPDATE:
Code on page as requested:
body {
background-color: #fff;
font-family:Arial, Helvetica, sans-serif;
color: #b7b8b9;
height: 100%;
width: 100%;
}
iframe{
border: none;
width: 100%;
/*margin-top: 50px;*/
}
#header{
height: 50px;
width: 100%;
}
<body>
<div id="wrapper">
<div id="header">
<div class="headerback">Home</div>
<div class="headerrefresh"><script>var pathname = window.location.pathname;</script><script>document.write('Refresh')</script></div>
<div class="headertitle"><h2>Get the Look</h2></div>
</div><!--HEADER-->
<iframe src="http://www.mbff.com.au/getthelook"></iframe>
</div>
</body>
Try to debug your page in Chrome (webkit) with the exact dimensions of your device. This solves most rendering issues for me.
I do not know the specific issue here, but it looks like one of your elements is flowing outside of the wrapper. You could for example try this in your css:
div.wrapper { overflow: hidden; width: inherit; }
Although it might be a better idea to find out why your page is expanding horizontally?
I was looking for the solution to this problem for a long time.
Finally I solved it in the following way.
I set style for bodyand html tags:
position: fixed;
width: 100%;
height: 100%;
overflow: hidden;
After that I've added div to body and set the style for it:
overflow-y: auto;
height: 100%;
So, I have got fixed body, which contains div with vertical scroll bar.
// Phone Gap disable only horizontal scrolling in Android.
// Add this code in your Phone Gap Main Activity.Initially Declare the variable
private float m_downX;
//Then add this code after loadUrl
this.appView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
// save the x
m_downX = event.getX();
}
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP: {
// set x so that it doesn't move
event.setLocation(m_downX, event.getY());
}
break;
}
return false;
}
});
Try adding the following code to your .html file:
document.body.addEventListener('touchmove', function(event) {
event.preventDefault();
}, false);
For the sake of completeness, I thought the answer which makes use of the official method of doing such a thing via the preference tag should be added:
<preference name="DisallowOverscroll" value="true"/>
Supported by Android and iOS according the documentation.
Default: false
Set to true if you don't want the interface to display any feedback when users scroll past the beginning or end of content. On iOS, overscroll gestures cause content to bounce back to its original position. on Android, they produce a more subtle glowing effect along the top or bottom edge of the content.
In my case it was broken styling like below
<body>
<div style="margin-left:5%; width:100%">Content</div>
</body>
which cause div to became horizontally bigger than body. I could see scroll when app run in browser. Set width to 90% (as it was initially intended) fixed the problem.
Generally, as it already pointed out here, enough to find element with wrong style which makes your page expanding horizontally and fix it.
BTW DisallowOverscroll was not helpful in above case.
I am trying to center align my google chart but have been unsuccessful in doing so. I have played with padding to move it to the center but I don't want to sit there and play with firebug for long time and figure out the correct position. Is there any simpler such as aligning text text-align: center. Obviously it doesn't work with google charts. (I am new to all of this)
var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
...some code ...
<div id='chart_div' style='width: 900px; height: 400px;'></div>
although I did this padding-left: 140px but is there any better way like align: center
Give the chart_div: display: block and margin: 0 auto;
You could also do <div id='chart_div' align='center'> This worked for me, although now my chart hovering function isn't working. Anyone else get this problem? I'm talking about when you hover the mouse over a point on the graph. It usually shows the point such as Jan Sales 440. Anyone know of a fix?
I have been facing the same issue with a google gauge. Checking the code generated I realized that the next thing inside the <div id='chart_div'> is a table with margin 0 set as inline style.
So in order to override it I used the following css:
div.chart_div table {
width: auto;
margin: 0 auto !important;
}
And this worked.
The accepted answer is broken; you have to use display: inline-block to center align your chart.
Since width is fixed, try setting margin-left and margin-right to auto. It should work assuming that the position is relative.
Any of these answers doesn't work for me so i did that:
<div class="chart_box">
<div id="chart_div" style='width: 900px; height: 400px;'></div>
</div>
.chart_box {
width: 900px;
margin: 0 auto;
}
You need to use same width for chart_div and chart_box.
Set chart_div to following properties:
#chart_div{
display: inline-block;
margin: 0 auto;
}
Notice: when you remove the side menu ("legend: 'none'") the width should be altered.
This happens mostly when you go "legend: 'none'" because it leaves the side space that was there to hold that menu, not adjusting the width automatically. You need to re set the width and NARROW it, to manipulate its alignment:
var options = {
title: 'center alignment',
width: 350,
height: 350,
legend: 'none'
};
I combined a few of the answers here, as follows:
Create a css class:
.customChartStyle{
border:1px solid #eee;
text-align:center !important;
}
and add it to the table's cells by adding the following to my table.draw() call:
'allowHtml': true, 'cssClassNames': {'tableCell': 'customChartStyle'}}
I'm new to google charts but the key for me was adding !important to the text-align style (thanks thanassis). For my case I needed the border style because overriding the tableCell style removed that otherwise. Also I prefer defining the class and letting the charts api apply it instead of overriding the styles generated by the api.
Subscribe to the ready event to modify the CSS with JavaScript. Something like below will do the trick.
google.charts.load('current', {
'packages': ['gauge']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Memory', 80],
['CPU', 55],
['Network', 68]
]);
var guageOptions = {
width: 400,
height: 120,
redFrom: 90,
redTo: 100,
yellowFrom: 75,
yellowTo: 90,
minorTicks: 5
};
var guage = new google.visualization.Gauge(document.getElementById('my-div'));
// HERE'S HOW TO SUBSCRIBE TO THE EVENT
google.visualization.events.addListener(guage, 'ready', resetTableStyle);
guage.draw(data, guageOptions);
// HERE'S THE JAVASCRIPT TO SET YOUR CSS
// NOTE TOGGLING A CSS CLASS HERE IS PROBABLY CLEANEST
function resetTableStyle(){
var myDiv = document.getElementById('my-div');
var myTable = myDiv.getElementsByTagName('table')[0];
myTable.style.margin = 'auto';
}
Below code works for me:
width:fit-content;
margin:0 auto;
By implementing a class to my div, it can now be centered.
HTML
<div id="chart_div2" class="chart_hum"></div>
CSS
.chart_hum {
margin: 0 auto;
display: inline-block;
}