Skip to content

Commit 1609c4b

Browse files
committed
Updated files
1 parent efa8434 commit 1609c4b

4 files changed

Lines changed: 40 additions & 47 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h1>Using Gemini and Google Maps Platform</h1>
4343

4444
<section class="container">
4545
<div class="container-header">
46-
<h2 class="output">(Results will appear here)</h2>
46+
<h2 class="output">(Results will appear here...)</h2>
4747

4848
<!-- <div class="weather-info">Weather data will be displayed here</div> -->
4949
</div>

names.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main.ts

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ form.addEventListener("submit", async (e) => {
109109
],
110110
});
111111

112-
await delay(60000); // This will wait for 60 seconds
112+
await delay(1000); // This will wait for 1 second
113113

114114
// Read from the stream and render the output
115115
const result = await model.generateContentStream({ contents });
@@ -169,36 +169,31 @@ function initMap() {
169169
* Sample: https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
170170
* Docs: https://developers.google.com/maps/documentation/javascript/geocoding
171171
*/
172-
async function geocodePlace(
173-
name: string
174-
): Promise<google.maps.GeocoderResult | void> {
175-
// prettier-ignore
172+
async function geocodePlace(name: string): Promise<google.maps.GeocoderResult> {
176173
const { Geocoder } = (await APILoader.importLibrary("geocoding")) as google.maps.GeocodingLibrary;
177-
178174
const geocoder = new Geocoder();
179175
const request = {
180176
address: name,
181177
};
182-
183178
try {
184-
// prettier-ignore
185-
const { LatLngAltitude } = (await APILoader.importLibrary("core")) as google.maps.CoreLibrary;
186-
const { results } = await geocoder.geocode(request);
179+
const { LatLngAltitude } = (await APILoader.importLibrary("core")) as google.maps.CoreLibrary;
180+
const { results } = await geocoder.geocode(request);
181+
if (!results || results.length === 0) {
182+
throw new Error("No results found for the given place name.");
183+
}
187184
const geocodedPlace = results[0];
188-
189185
const newCenter = new LatLngAltitude({
190186
lat: geocodedPlace.geometry.location.lat() - 0.005,
191187
lng: geocodedPlace.geometry.location.lng(),
192188
altitude: 200,
193-
});
194-
map.center = newCenter;
195-
map.heading = 0;
196-
197-
return geocodedPlace;
198-
} catch (error) {
199-
console.log(
200-
"Geocode was not successful for the following reason: " + error
201-
);
189+
});
190+
map.center = newCenter;
191+
map.heading = 0;
192+
return geocodedPlace;
193+
} catch (error: unknown) {
194+
const errorMessage = error instanceof Error ? error.message : String(error);
195+
console.error("Geocode was not successful for the following reason: " + errorMessage);
196+
throw new Error("Geocoding failed: " + errorMessage);
202197
}
203198
}
204199

@@ -210,35 +205,37 @@ async function geocodePlace(
210205
* 2. Search nearby
211206
* - Sample and Docs: https://developers.google.com/maps/documentation/javascript/nearby-search
212207
*/
213-
async function findNearbyLodging(location: google.maps.LatLng) {
214-
// prettier-ignore
215-
const { Place, SearchNearbyRankPreference } = (await APILoader.importLibrary("places")) as google.maps.PlacesLibrary;
216-
217-
// use Place.searchNearby to find lodging with a location bias of location
218-
const request: google.maps.places.SearchNearbyRequest = {
219-
// required parameters
220-
fields: ["id", "location"],
221-
locationRestriction: {
222-
center: location,
223-
radius: 10000,
224-
},
225-
// optional parameters
226-
includedTypes: ["lodging"],
227-
maxResultCount: 10,
228-
rankPreference: SearchNearbyRankPreference.POPULARITY,
229-
};
230-
208+
async function findNearbyLodging(location: google.maps.LatLng): Promise<void>
209+
{
210+
const { Place, SearchNearbyRankPreference } = (await APILoader.importLibrary("places")) as google.maps.PlacesLibrary;
211+
const request: google.maps.places.SearchNearbyRequest = {
212+
fields: ["id", "location", "displayName"],
213+
locationRestriction: {
214+
center: location,
215+
radius: 10000,
216+
},
217+
includedTypes: ["lodging"],
218+
maxResultCount: 10,
219+
rankPreference: SearchNearbyRankPreference.POPULARITY,
220+
};
221+
try {
231222
const { places } = await Place.searchNearby(request);
232-
233223
if (places.length) {
234224
console.log(`found ${places.length} lodging`);
235-
236225
addResults(places);
237-
} else {
238-
console.log("No results");
226+
} else {
227+
console.log("No lodging results found.");
228+
// Optionally, throw an error if no results is considered an error condition
229+
}
230+
} catch (error: unknown) {
231+
const errorMessage = error instanceof Error ? error.message :
232+
String(error);
233+
console.error("Search for nearby lodging failed: " + errorMessage);
234+
throw new Error("Failed to find nearby lodging: " + errorMessage);
239235
}
240236
}
241237

238+
242239
/*
243240
* Add and populate a Place Overview component in a Split Layout with the map
244241
* Documentation (install Extended Component Library): https://github.com/googlemaps/extended-component-library/tree/main#installation

to-do.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)