-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
30 lines (29 loc) · 1.44 KB
/
map.js
File metadata and controls
30 lines (29 loc) · 1.44 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
const apiKey = 'AIzaSyCHAJJ5XH4PYYCDaUhJ3Ovr73VHQIIIS1c'; // google map API
const openWeatherApiKey = "dbb76c5d98d5dbafcb94441c6a10236e";
//1 getCurrentPosition
$('#location-button').click(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
// console.log(position);
//2 get city name
getCityName(position)
});
}
});
//2 get city name
const getCityName = async (position) => { // === async function getCityName(postion) {}
const {latitude, longitude} = position.coords;
const response = await fetch(`https://api.openweathermap.org/geo/1.0/reverse?lat=${latitude}&lon=${longitude}&appid=${openWeatherApiKey}`, {
method: 'GET'
});
const data = await response.json();
const {name: city} = data[0] // === 'const city = data[0].name'
// 3 in city
const mapI = document.querySelector('#map');
mapI.setAttribute('style', 'width:95%; height:70vh');
mapI.setAttribute('src', `https://www.google.com/maps/embed/v1/search?q=record+movietheater+in+${city}&key=${apiKey}&zoom=12¢er=${latitude},${longitude}`);
}
// dan: https://developers.google.com/maps/documentation/embed/embedding-map
const mapI = document.querySelector('#map');
mapI.setAttribute('style', 'width:95%; height:70vh');
mapI.setAttribute('src', `https://www.google.com/maps/embed/v1/search?q=record+movietheater+in+seattle&key=${apiKey}&zoom=12`);