Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting http/https protocols to match with <iframe> for maps.google.com

Tags:

I am trying to use an <iframe> include of a google map, however the console is throwing several errors due to a mismatch, but there is no apparent mismatch, so I'm assuming it must be a function/process on the side of google maps.

Specifically with maps.google.com, there appears to be a change to the script for the iframe, according to this.

The errors in the console is this: ( I am getting at least 30 errors on page load )

Unsafe JavaScript attempt to access frame with URL http://www.developer.host.com/ from frame with URL https://maps.google.com/maps/msmsa=0&msid= 212043342089249462794.00048cfeb10fb9d85b995&ie=UTF8&t= m&ll=35.234403,-80.822296&spn=0.392595,0.137329&z=10&output=embed.   The frame requesting access has a protocol of 'https', the frame being accessed has a protocol of 'http'. Protocols must match. 

Since my site is http and NOT https, and the map url is http, why is the mismatch occuring, and how do I fix this to make them match?

like image 836
chris Frisina Avatar asked Nov 25 '12 20:11

chris Frisina


People also ask

How do you the Google Maps Embed API must be used in an iframe?

The short answer is, use a web page to embed an iframe and load the web page in Tableau. Simply append this in front of your Google Maps URL in Tableau and it should work for you. Thanks for all your work on this solution.


1 Answers

This really is a bug of the embeddable HTML code, created by the standalone Google Maps page (maps.google.com -> click on link chain button to get the iframe based HTML code).
As said by aSeptik in the comments to your question, the corresponding bug report can be found here.

You can avoid that bug if you embed a Google Map using the Maps API. It does make no difference if you use the Maps API directly in your page or within an embedded iframe - both ways work fine.

Here is an example of some other map where I have used the Maps API within an iframe.

And here is an example of your own map using the Maps API - embedded right within the page.

The additional code needed for the Maps API is actually very small:

<html> <head>     <script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>     <script type='text/javascript' src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>     <script type='text/javascript'>         $(function(){             var myOptions = {                 center: new google.maps.LatLng(35.201867,-80.836029),                 zoom: 10,                 mapTypeId: google.maps.MapTypeId.ROADMAP             };             gMap = new google.maps.Map(document.getElementById('map_canvas'), myOptions);              var kmlLayer = new google.maps.KmlLayer('https://maps.google.com/maps/ms?ie=UTF8&t=m&authuser=0&msa=0&output=kml&msid=212043342089249462794.00048cfeb10fb9d85b995');             kmlLayer.setMap(gMap);         });     </script> </head> <body>     <div id="map_canvas" style="width: 400px; height: 400px;"></div> </body> 

I have used jQuery here for convenience.

like image 85
Jpsy Avatar answered Oct 09 '22 11:10

Jpsy