Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube video in a Google Map Info Window

I am trying to put a youtube video into a Google Map (v3) Info Window.

It works fine in Firefox and Internet Explorer.

It does not work in Safari and Chrome. In those browsers the positioning is off and the video doesn't move when you move the map. The video also gets chopped sometimes.

Here is the code that doe

<!doctype html>
<html>
<head>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
var map;
function initialize() {
    latlng = new google.maps.LatLng(33.4222685, -111.8226402)
    myOptions = {
      zoom: 4,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map"),myOptions)
    var point = new google.maps.LatLng(33.4222685, -111.8226402);
    var marker = new google.maps.Marker({
        position: point,
        map: map
    })
    google.maps.event.addListener(marker, "click", function(){
        bubble = new google.maps.InfoWindow({
          content: '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/UmFjNiiVk9w?fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/UmFjNiiVk9w?fs=1" type="application/x-shockwave-flash" width="425" height="344" allowscriptaccess="always" allowfullscreen="true"></embed></object>'
        })
        bubble.open(map, marker);
    })
}
</script>
</head>
<body onload="initialize();">
  <div id="map" style="width: 984px; height: 495px"></div>
</div>
</body>
</html>

An example of it working fine for the Google Maps API version 2 is here http://www.virtualvideomap.com/

Also on http://maps.google.com You can see youtube videos inside the Info Window working in Chrome and Safari by clicking "More..." on the top right of the map, and then checking "Videos".

like image 491
Drew LeSueur Avatar asked Sep 12 '10 08:09

Drew LeSueur


People also ask

How do I use Google Maps and YouTube at the same time?

Connecting YouTube Music to Google Maps 2 or higher. And this works on both Android and iOS. To set up, Open Google Maps > Settings > Navigation Settings > and enable “Show media playback controls”.


2 Answers

This is a webkit bug, but you can find a solution here: http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/ccaaee32b89e3656/c87bb19e4662bd78#c87bb19e4662bd78

like image 126
skarE Avatar answered Sep 18 '22 12:09

skarE


Got a partial solution, use the iframe embed mode sorted the problem out to me!

Hope it helps!!

<!doctype html>
<html>
<head>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
var map;
function initialize() {
    latlng = new google.maps.LatLng(33.4222685, -111.8226402)
    myOptions = {
      zoom: 4,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map"),myOptions)
    var point = new google.maps.LatLng(33.4222685, -111.8226402);
    var marker = new google.maps.Marker({
        position: point,
        map: map
    })
    google.maps.event.addListener(marker, "click", function(){
        bubble = new google.maps.InfoWindow({
          content: '<iframe title="YouTube video player" class="youtube-player" type="text/html" width="480" height="390" src="http://www.youtube.com/embed/UmFjNiiVk9w?rel=0" frameborder="0"></iframe>'
        })
        bubble.open(map, marker);
    })
}
</script>
</head>
<body onload="initialize();">
  <div id="map" style="width: 984px; height: 495px"></div>
</div>
</body>
</html>
like image 32
Trufa Avatar answered Sep 20 '22 12:09

Trufa