2017-01-16 22 views

回答

1

也許是這樣的:

<!DOCTYPE html> 
<html> 
    <head><title>test</title></head> 
    <body> 
    <iframe 
    width="600" 
    height="450" 
    frameborder="0" style="border:0" 
    src="https://www.google.com/maps/embed/v1/place?key=AIzaSyBu9SPYB9qp2PTe1M1_TyBAQN4c-yL8HYQ 
    &q=Space+Needle,Seattle+WA&zoom=10" allowfullscreen> 
</iframe> 
    <script> 
     function setEmbeddedMapZoom() { 
      var zoomForPhone = 15; 
      var defaultZoom = 10; 
      var baseSrc = 'https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY&q=Space+Needle,Seattle+WA&zoom='; 
      if (window.innerWidth < 1600) { 
       document.getElementsByTagName('iframe')[0].setAttribute('src', baseSrc + zoomForPhone); 
      } else { 
       document.getElementsByTagName('iframe')[0].setAttribute('src', baseSrc + defaultZoom); 
      } 
     } 

     window.addEventListener('resize', setEmbeddedMapZoom); 
    </script> 
    </body> 
</html> 

http://jsbin.com/tucanayiye/edit?html,output

請注意,我必須確保嵌入API是在我創建的API密鑰項目開啓。