-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapp.tsx
More file actions
94 lines (79 loc) · 3.01 KB
/
app.tsx
File metadata and controls
94 lines (79 loc) · 3.01 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
{/* [START maps_react_ui_kit_place_details_by_latlng] */}
import React from 'react';
import {createRoot} from 'react-dom/client';
import {APIProvider, useMapsLibrary} from '@vis.gl/react-google-maps';
import './styles.css';
const API_KEY = "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8";
type PlaceDetailsProps = {
lat: number;
lng: number;
};
// Renders place details using a latitude and longitude.
const PlaceDetails = ({lat, lng}: PlaceDetailsProps) => {
const places = useMapsLibrary('places');
const containerRef = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (!places || !containerRef.current) {
return;
}
// Create the gmp-place-details element.
const placeDetails = document.createElement('gmp-place-details');
// Create the gmp-place-details-location-request element.
const locationRequest = document.createElement(
'gmp-place-details-location-request',
);
// Set the location on the location request element.
locationRequest.setAttribute('location', `${lat},${lng}`);
// Append the location request to the place details element.
placeDetails.appendChild(locationRequest);
// Create and append the content config and its children.
const contentConfig = document.createElement('gmp-place-content-config');
contentConfig.innerHTML = `
<gmp-place-address></gmp-place-address>
<gmp-place-rating></gmp-place-rating>
<gmp-place-type></gmp-place-type>
<gmp-place-price></gmp-place-price>
<gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon>
<gmp-place-opening-hours></gmp-place-opening-hours>
<gmp-place-website></gmp-place-website>
<gmp-place-phone-number></gmp-place-phone-number>
<gmp-place-summary></gmp-place-summary>
<gmp-place-type-specific-highlights></gmp-place-type-specific-highlights>
<gmp-place-reviews></gmp-place-reviews>
<gmp-place-feature-list></gmp-place-feature-list>
<gmp-place-media lightbox-preferred></gmp-place-media>
<gmp-place-attribution
light-scheme-color="gray"
dark-scheme-color="white"></gmp-place-attribution>
`;
placeDetails.appendChild(contentConfig);
// Append the place details element to the container.
containerRef.current.innerHTML = ''; // Clear previous content
containerRef.current.appendChild(placeDetails);
}, [places, lat, lng]);
return <div ref={containerRef} className="place-details-container" />;
};
const App = () => {
return (
<APIProvider apiKey={API_KEY} libraries={['places']}>
<div className="places-ui-kit">
<PlaceDetails lat={48.8566} lng={2.3522} />
</div>
</APIProvider>
);
};
export default App;
export function renderToDom(container: HTMLElement) {
const root = createRoot(container);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
}
{/* [END maps_react_ui_kit_place_details_by_latlng] */}