JAVASCRIPT - Displaying a map tutorial


SUBMITTED BY: efbee

DATE: Oct. 5, 2016, 7:05 p.m.

FORMAT: JavaScript

SIZE: 968 Bytes

HITS: 1184

  1. *** HTML CODE ***
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5.    <style>
  6.  
  7.    #map {
  8.  
  9.         width:  500px;
  10.  
  11.         height: 500px;
  12.  
  13.       }
  14.    </style>
  15.  
  16. </head>
  17. <body>
  18.    <h1>A Google Map</h1>
  19.    <p>Center of downtown in Indianapolis, IN </p>
  20.    <div id="map"></div>
  21.    <script src="js/google-map.js"></script>
  22. </body>
  23. </html>
  24.  
  25.  
  26. *** JavaScript code (in attached file) ***
  27. // JavaScript source code
  28. function init() {
  29.     var mapOptions = {
  30.         center: new google.maps.LatLng(39.7685571, -86.1578993, 19),
  31.         mapTypeId: google.maps.MapTypeId.SATELLITE,
  32.         zoom: 18
  33.     };
  34.  
  35.     var myMap;
  36.     myMap = new google.maps.Map(document.getElementById('map'), mapOptions);
  37. }
  38.  
  39. function loadScript() {
  40.     var script = document.createElement('script');
  41.     script.src = 'http://maps.googleapis.com/maps/api/js?sensor=false&callback=init';
  42.     document.body.appendChild(script);                
  43. }
  44.  
  45. window.onload = loadScript;

comments powered by Disqus