Place Searches

by chinmaysharma01

HTML

<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyARbDtBazTZTGrmxsIuCJHAQLdsPiAsXkw&libraries=places&callback=initMap" async defer></script>

CSS

/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */
#map {
  height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

JavaScript

// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
var myList = ['','Canon Kontor ','DNB','Handelsbanken','Rica Eiendom','Storebrand','Radisson Hotels Norway','Caverion','Color Line','DNV GL','SAS','Select Service Partner','Gress-Gruppen','NHG Management','Hurtigruten','Compass Group','Radisson Blu Scandinavia Hotel','Park Inn Oslo Airport','Park Inn Oslo','Radisson Blu Airport Hotel','Radisson Blu Hotel Alna','Radisson Blu Plaza Hotel','Stamina Helse'];
var i = 1;
var map;
var service;
var infowindow;
var k=0;
    
function initMap() {
  var mapCenter = new google.maps.LatLng(-33.8617374,151.2021291);

  map = new google.maps.Map(document.getElementById('map'), {
    center: mapCenter,
    zoom: 15
  });
  
  
		myLoop();
  
  
}

function callback(results, status) {
//console.log(results);
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      var place = results[i];
      console.log(results[i].name+';'+results[i].formatted_address+';'+results[i].geometry.location.lat()+';'+results[i].geometry.location.lng());
    }
  }
}
                 //  set your counter to 1

function myLoop () {           //  create a loop function
   setTimeout(function () {    //  call a 3s setTimeout when the loop is called
      
  console.log(myList[i]);
  	var request = {
    query: myList[i],
    fields: ['photos', 'formatted_address', 'name', 'rating', 'opening_hours', 'geometry'],
  };

  service = new google.maps.places.PlacesService(map);
  service.findPlaceFromQuery(request, callback);   //  your code here
      i++;                     //  increment the counter
      if (i < myList.length) {            //  if the counter < 10, call the loop function
         myLoop();             //  ..  again which will trigger another 
      }                     ...