-
Notifications
You must be signed in to change notification settings - Fork 823
/
index.js
66 lines (58 loc) · 1.66 KB
/
index.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @license
* Copyright 2022 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_place_text_search]
let map;
let center;
async function initMap() {
const { Map } = await google.maps.importLibrary("maps");
center = { lat: 37.4161493, lng: -122.0812166 };
map = new Map(document.getElementById("map"), {
center: center,
zoom: 11,
mapId: "DEMO_MAP_ID",
});
findPlaces();
}
async function findPlaces() {
const { Place } = await google.maps.importLibrary("places");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
// [START maps_place_text_search_request]
const request = {
textQuery: "Tacos in Mountain View",
fields: ["displayName", "location", "businessStatus"],
includedType: "restaurant",
locationBias: { lat: 37.4161493, lng: -122.0812166 },
isOpenNow: true,
language: "en-US",
maxResultCount: 8,
minRating: 3.2,
region: "us",
useStrictTypeFiltering: false,
};
//@ts-ignore
const { places } = await Place.searchByText(request);
// [END maps_place_text_search_request]
if (places.length) {
console.log(places);
const { LatLngBounds } = await google.maps.importLibrary("core");
const bounds = new LatLngBounds();
// Loop through and get all the results.
places.forEach((place) => {
const markerView = new AdvancedMarkerElement({
map,
position: place.location,
title: place.displayName,
});
bounds.extend(place.location);
console.log(place);
});
map.fitBounds(bounds);
} else {
console.log("No results");
}
}
initMap();
// [END maps_place_text_search]