Advertisement
citstudio

Multiple Maps

Mar 5th, 2015
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function initialize() {
  2.     var map;
  3.     var bounds = new google.maps.LatLngBounds();
  4.     var mapOptions = {
  5.         mapTypeId: google.maps.MapTypeId.ROADMAP,
  6.         mapTypeControl: false,
  7.         streetViewControl: false,
  8.         panControl: false,
  9.         zoomControlOptions: {
  10.             position: google.maps.ControlPosition.LEFT_BOTTOM
  11.         }
  12.     };
  13.                    
  14.             // Display a map on the page
  15.     map = new google.maps.Map(document.getElementById("map"), mapOptions);
  16.     map.setTilt(15);
  17.    
  18.     var markers = viewlocations;
  19.          
  20.     // Info Window Content
  21.             var infoWindowContent = locationsContent;
  22.        
  23.     // Display multiple markers on a map
  24.             var infoWindow = new google.maps.InfoWindow(), marker, i;
  25.    
  26.     // Loop through our array of markers & place each one on the map  
  27.             for( i = 0; i < markers.length; i++ ) {
  28.                 var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
  29.                 bounds.extend(position);
  30.                 marker = new google.maps.Marker({
  31.                     position: position,
  32.                     map: map,
  33.                     title: markers[i][0],
  34.                     icon: markers[i][3]
  35.                 });
  36.        
  37.         // Allow each marker to have an info window    
  38.             google.maps.event.addListener(marker, 'click', (function(marker, i) {
  39.                 return function() {
  40.                     infoWindow.setContent(infoWindowContent[i][0]);
  41.                     infoWindow.open(map, marker);
  42.                 }
  43.             })(marker, i));
  44.  
  45.         // Automatically center the map fitting all markers on the screen
  46.             map.fitBounds(bounds);
  47.         }
  48.  
  49.     // Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
  50.         var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
  51.             this.setZoom(13);
  52.             this.setCenter(new google.maps.LatLng(-6.9090815, 107.617204));
  53.             google.maps.event.removeListener(boundsListener);
  54.         });
  55.    
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement