You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert

231
+
232
+
## Add a search component
233
+
234
+
Now we can try adding a search bar to your map which can return results and place markers on a map based on those results.
235
+
236
+
<BlockSwitcher>
237
+
238
+
<Blockname="Amplify">
239
+
240
+
With Amplify Geo and MapLibre you can do the following.
241
+
242
+
```js
243
+
const { createMap, createAmplifyGeocoder } = AmplifyMapLibre; // import from above updated to include createAmplifyGeocoder
244
+
245
+
constgeocoder=createAmplifyGeocoder();
246
+
map.addControl(geocoder);
247
+
```
248
+
249
+
Save your changes and refresh your page and now when you should see a maplibre-gl-geocoder control in the top right corner of your map.
250
+
251
+
<Callout>
252
+
253
+
This example uses the [MapLibre's geocoder component](https://github.com/maplibre/maplibre-gl-geocoder) to create a search component. To see more options for our `createAmplifyGeocoder` utility function check out the docs [here](https://github.com/aws-amplify/maplibre-gl-js-amplify/blob/main/API.md#createAmplifyGeocoder).
254
+
255
+
</Callout>
256
+
257
+
</Block>
258
+
259
+
<Blockname="Google Maps">
260
+
261
+
Using the Google Places JS API you would add a search bar as shown below.
262
+
263
+
```js
264
+
// Create the search box and link it to the UI element.
265
+
constinput=document.getElementById("pac-input") as HTMLInputElement;
Save your changes and refresh your page and now when you should see a maplibre-gl-geocoder control in the div you created.
320
+
321
+
<Callout>
322
+
323
+
This example uses the [MapLibre's geocoder component](https://github.com/maplibre/maplibre-gl-geocoder) to create a search component. To see more options for our `createAmplifyGeocoder` utility function check out the docs [here](https://github.com/aws-amplify/maplibre-gl-js-amplify/blob/main/API.md#createAmplifyGeocoder).
324
+
325
+
</Callout>
326
+
327
+
</Block>
328
+
329
+
<Blockname="Google Maps">
330
+
331
+
Using the Google Places JS API you would add a stand alone search bar as shown below.
332
+
333
+
<Callout>
334
+
335
+
Some lines omitted for brevity, see the Google Maps Platform Places Search Box example for the full application
336
+
337
+
</Callout>
338
+
339
+
```js
340
+
// Create a input to hold the search component
341
+
constel=document.createElement("input");
342
+
el.setAttribute("id", "pac-input");
343
+
document.body.appendChild(el);
344
+
345
+
// Create the search box and link it to the UI element.
0 commit comments