-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathfindLocation.js
More file actions
29 lines (22 loc) · 894 Bytes
/
findLocation.js
File metadata and controls
29 lines (22 loc) · 894 Bytes
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 findMyState = () => {
const status = document.querySelector('.status');
const success =(position)=>{
console.log(position)
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
console.log(latitude+' '+longitude);
const geoApiUrl = `https://api.bigdatacloud.net/data/reverse-geocode-client?latitude=${latitude}&longitude=${longitude}&localityLanguage=en`
fetch(geoApiUrl)
.then(res => res.json())
.then(data=> {
console.log(data)
status.textContent = data.countryName
})
}
const error =()=>{
status.textContent = 'unable to retreive your location'
console.log(position)
}
navigator.geolocation.getCurrentPosition(success, error);
}
document.querySelector('.find-state').addEventListener('click', findMyState );