blob: 6bc27f291419168458ebd7ec005f60aac0ebc761 (
plain) (
blame)
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
|
const { ADDRESS, MAPS_API_KEY } = CONF_OBJECT;
const mapPlace = document.getElementById("map");
const displayMap = (address) => {
const urlAddress = encodeURI(address);
fetch(
`https://maps.googleapis.com/maps/api/geocode/json?address=${urlAddress}&key=${MAPS_API_KEY}`
)
.then((res) => res.json())
.then((json) => {
const coordinates = json.results[0].geometry.location;
const map = new google.maps.Map(mapPlace, {
center: coordinates,
zoom: 12,
});
new google.maps.Marker({
position: coordinates,
map,
});
})
.catch((err) => {
throw new Error(err);
});
};
if (mapPlace) {
displayMap(ADDRESS);
}
|