-
Notifications
You must be signed in to change notification settings - Fork 1
/
places.js
31 lines (26 loc) · 862 Bytes
/
places.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const request = {
location: new google.maps.LatLng(51.5287352, -0.3817841),
radius: 5000,
type: ['restaurant']
};
const results = [];
const places = document.getElementById('places');
const service = new google.maps.places.PlacesService(places);
const callback = (response, status, pagination) => {
if (status == google.maps.places.PlacesServiceStatus.OK) {
results.push(...response);
}
if (pagination.hasNextPage) {
setTimeout(() => pagination.nextPage(), 2000);
} else {
displayResults();
}
}
const displayResults = () => {
results.filter(result => result.rating)
.sort((a, b) => a.rating > b.rating ? -1 : 1)
.forEach(result => {
places.innerHTML += `<li>${result.name} - ${result.rating}</li>`;
});
}
service.nearbySearch(request, callback);