Advertisement
eimkasp

Untitled

Oct 17th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div id="map"></div>
  2. <script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js">
  3.     </script>  
  4.     <script>
  5.  
  6.       var infowindow = null;
  7.       var map = null;
  8.       var markerclusterer = null;
  9.       var markers = [];
  10.       var mcOptions = {styles: [{
  11.                     height: 56,
  12.                     url: "https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m1.png",
  13.                     width: 55
  14.                     },
  15.                     {
  16.                     height: 56,
  17.                     url: "https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m2.png",
  18.                     width: 55
  19.                     },
  20.                     {
  21.                     height: 56,
  22.                     url: "https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m3.png",
  23.                     width: 55
  24.                     },
  25.                     {
  26.                     height: 56,
  27.                     url: "https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m4.png",
  28.                     width: 55
  29.                     },
  30.                     {
  31.                     height: 56,
  32.                     url: "https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m5.png",
  33.                     width: 55
  34.                     }],
  35.                     gridSize: 50,
  36.                     maxZoom: 15
  37.                   }
  38.      
  39.       function initMap() {
  40.         var mapDiv = document.getElementById('map');
  41.         map = new google.maps.Map(mapDiv, {
  42.             center: {lat: 55.298478, lng: 23.9130441},
  43.             zoom: 7,
  44.             scrollwheel: false,
  45.             navigationControl: false,
  46.             mapTypeControl: false,
  47.             scaleControl: false
  48.         });
  49.  
  50.        
  51.         var markerCluster = new MarkerClusterer(map, markers, mcOptions);
  52.         infowindow = new google.maps.InfoWindow({
  53.           content: "holding..."
  54.           });
  55.         jQuery(document).ready(function(){
  56.             var clinics = [
  57.                 {
  58.                     "address" : "Kaunas",
  59.                     "name" : "pirma",
  60.                     "phone" : "111",
  61.                     "permalink" : "http://json.org/example.html",
  62.                     "web" : "http://json.org/example.html",
  63.                     "thumb" : "http://odontologija.tit.lt/wp-content/themes/odontologas/img/default-thumbnail.png"
  64.                 },
  65.                 {
  66.                     "address" : "Vilnius",
  67.                     "name" : "antra",
  68.                     "phone" : "222",
  69.                     "permalink" : "http://json.org/example.html",
  70.                     "web" : "http://json.org/example.html",
  71.                     "thumb" : "http://odontologija.tit.lt/wp-content/themes/odontologas/img/default-thumbnail.png"
  72.                 }
  73.             ];
  74.  
  75.             var clinicNumber = 0;
  76.             // var addresses = ['Kaunas', 'Vilnius', 'Palanga','Klaipeda','Siauliai'];
  77.  
  78.              for (var x = 0; x < clinics.length; x++) {
  79.                jQuery.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address='+clinics[x].address+'&sensor=false', null, function (data) {
  80. clinicNumber++;
  81.                     console.log(clinics);
  82.                     var p = data.results[0].geometry.location;
  83.                     var marker = new google.maps.Marker({
  84.                         position: p,
  85.                         map: map,
  86.                         html: `<div class="map-klinika">
  87.                           <div class="col-md-3 map-img"><img src="<?php echo get_template_directory_uri(); ?>/img/default-thumbnail.png"></div>
  88.                           <div class="col-md-9">
  89.                               <div class="map-klinika-header">`+clinics[clinicNumber].name+`</div>
  90.                               <div class="map-klinika-adresas">Adreso g. 56, Kaunas</div>
  91.                               <div class="map-email"><a href="#"><img src="<?php echo get_template_directory_uri(); ?>/img/email-icon.png">EL. PAŠTAS</a></div>
  92.                               <div class="map-web"><a href="#"><img src="<?php echo get_template_directory_uri(); ?>/img/web-icon.png">TINKLALAPIS</a></div>
  93.                               <div class="map-phone">86112113321</div>
  94.                           </div>
  95.                   </div>`
  96.                     });
  97.                     markers.push(marker);
  98.                     markerCluster.addMarker(marker);
  99.                     google.maps.event.addListener(marker, 'click', function () {
  100.                     // where I have added .html to the marker object.
  101.                     infowindow.setContent(this.html);
  102.                     infowindow.open(map, this);
  103.                     });
  104.                 });
  105.                
  106.             }
  107.            
  108.         }); // jquery
  109.  
  110.        
  111.          
  112.         // var markers = locations.map(function(location, i) {
  113.         //   return new google.maps.Marker({
  114.         //     position: location,
  115.         //     html: `<div class="map-klinika">
  116.         //                   <div class="col-md-3 map-img"><img src="<?php echo get_template_directory_uri(); ?>/img/default-thumbnail.png"></div>
  117.         //                   <div class="col-md-9">
  118.         //                       <div class="map-klinika-header">Pavadinimas</div>
  119.         //                       <div class="map-klinika-adresas">Adreso g. 56, Kaunas</div>
  120.         //                       <div class="map-email"><a href="#"><img src="<?php echo get_template_directory_uri(); ?>/img/email-icon.png">EL. PAŠTAS</a></div>
  121.         //                       <div class="map-web"><a href="#"><img src="<?php echo get_template_directory_uri(); ?>/img/web-icon.png">TINKLALAPIS</a></div>
  122.         //                       <div class="map-phone">86112113321</div>
  123.         //                   </div>
  124.         //           </div>`
  125.         //     // icon: image
  126.         //   });
  127.         // });
  128.        
  129.         // for (var i = 0; i < markers.length; i++) {
  130.         //         var marker = markers[i];
  131.         //         google.maps.event.addListener(marker, 'click', function () {
  132.         //         // where I have added .html to the marker object.
  133.         //         infowindow.setContent(this.html);
  134.         //         infowindow.open(map, this);
  135.         //         });
  136.         //     }
  137.        
  138.         // {imagePath: "https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m2"}
  139.          
  140.        
  141.       }
  142.     </script>
  143.    
  144. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDtLyzDbRGyg_FibPybiKOQwUyxRvJlSFc&callback=initMap"
  145.     async defer></script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement