<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=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&libraries=places&callback=initMap" async defer></script>
// 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 map;
var service;
var infowindow;
var resultsArray = [];
var bounds;
function initMap() {
bounds = new google.maps.LatLngBounds();
infowindow = new google.maps.InfoWindow();
map = new google.maps.Map(
document.getElementById('map'));
var points = [
[2.627365, 49.215369],
[2.760591, 49.647163],
[2.952975, 50.057504],
[3.344742, 50.280862],
[3.768293, 50.451306],
[4.21659, 50.534029]
]
var i = 0;
for (point of points) {
googlePlaces(point, i);
i++;
}
setTimeout(function() {
console.log(resultsArray);
}, 10000);
}
function googlePlaces(point, index) {
var latLng = new google.maps.LatLng(point[1], point[0])
var request = {
location: latLng,
radius: '10000'
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, function(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
resultsArray[index] = results; // ...then hits this code [i] times
for (var i = 0; i < results.length; i++) {
var marker = createMarker(results[i], "search " + index);
bounds.extend(marker.getPosition());
}
map.fitBounds(bounds);
}
})
}
function createMarker(place, text) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(text + "<br>" + place.name);
infowindow.open(map, this);
});
return marker;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.