-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Place class and searchByText (#63)
- Loading branch information
Showing
9 changed files
with
555 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// This example showcases the new Places API. | ||
// | ||
// This is meant to be showcased as the client logic that is able to remain untouched | ||
// and retain the same functionality when using the migration adapter. | ||
|
||
const austinCoords = { lat: 30.268193, lng: -97.7457518 }; // Austin, TX :) | ||
|
||
let map; | ||
let center; | ||
|
||
async function initMap() { | ||
const { Map } = await google.maps.importLibrary("maps"); | ||
|
||
map = new Map(document.getElementById("map"), { | ||
center: austinCoords, | ||
zoom: 11, | ||
mapId: "DEMO_MAP_ID", | ||
}); | ||
|
||
findPlaces(); | ||
} | ||
|
||
async function findPlaces() { | ||
const { Place } = await google.maps.importLibrary("places"); | ||
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); | ||
const request = { | ||
textQuery: "Whataburger in Austin", | ||
fields: ["displayName", "location", "utcOffsetMinutes"], | ||
locationBias: austinCoords, | ||
language: "en-US", | ||
maxResultCount: 15, | ||
}; | ||
|
||
const { places } = await Place.searchByText(request); | ||
|
||
if (places.length) { | ||
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); | ||
}); | ||
map.fitBounds(bounds); | ||
} else { | ||
console.log("No results"); | ||
} | ||
} | ||
|
||
initMap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<html> | ||
<head> | ||
<title>New Places Example - Google</title> | ||
<link rel="stylesheet" type="text/css" href="../common/style.css" /> | ||
|
||
<!-- jQuery imports for example --> | ||
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css" /> | ||
<script src="https://code.jquery.com/jquery-3.6.0.js"></script> | ||
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script> | ||
|
||
<!-- Client logic example --> | ||
<script type="module" src="./example.js"></script> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
|
||
<!-- Google Maps API import --> | ||
<script> | ||
((g) => { | ||
var h, | ||
a, | ||
k, | ||
p = "The Google Maps JavaScript API", | ||
c = "google", | ||
l = "importLibrary", | ||
q = "__ib__", | ||
m = document, | ||
b = window; | ||
b = b[c] || (b[c] = {}); | ||
var d = b.maps || (b.maps = {}), | ||
r = new Set(), | ||
e = new URLSearchParams(), | ||
u = () => | ||
h || | ||
(h = new Promise(async (f, n) => { | ||
await (a = m.createElement("script")); | ||
e.set("libraries", [...r] + ""); | ||
for (k in g) | ||
e.set( | ||
k.replace(/[A-Z]/g, (t) => "_" + t[0].toLowerCase()), | ||
g[k], | ||
); | ||
e.set("callback", c + ".maps." + q); | ||
a.src = `https://maps.${c}apis.com/maps/api/js?` + e; | ||
d[q] = f; | ||
a.onerror = () => (h = n(Error(p + " could not load."))); | ||
a.nonce = m.querySelector("script[nonce]")?.nonce || ""; | ||
m.head.append(a); | ||
})); | ||
d[l] | ||
? console.warn(p + " only loads once. Ignoring:", g) | ||
: (d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))); | ||
})({ | ||
key: "{{GOOGLE_API_KEY}}", | ||
v: "weekly", | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<html> | ||
<head> | ||
<title>New Places Example - Migration Adapter</title> | ||
<link rel="stylesheet" type="text/css" href="../common/style.css" /> | ||
|
||
<!-- jQuery imports for example --> | ||
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css" /> | ||
<script src="https://code.jquery.com/jquery-3.6.0.js"></script> | ||
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script> | ||
|
||
<!-- Client logic example --> | ||
<script type="module" src="./example.js"></script> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
|
||
<!-- Migration script import --> | ||
<script src="../../dist/amazonLocationMigrationAdapter.js?region={{REGION}}&map={{MAP_NAME}}&placeIndex={{PLACE_INDEX}}&apiKey={{AMAZON_LOCATION_API_KEY}}"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.