-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
70 lines (55 loc) · 1.44 KB
/
Copy pathapp.js
File metadata and controls
70 lines (55 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
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
let latitude ,longitude ="";
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(onSuccess,onError);
}
else
{
alert("Tarayici konum bilgisini alamiyor");
}
function onSuccess(position)
{
latitude=position.coords.latitude;
longitude=position.coords.longitude;
initMap();
const api_key = "YOUR_API_KEY_HERE";
const url = `https://api.opencagedata.com/geocode/v1/json?q=${latitude}+${longitude}&key=${api_key}`;
fetch(url)
.then(response => response.json())
.then(result=>{
let details=result.results[0].components;
let {country ,postcode ,province}=details;
document.getElementById("results").innerHTML=`
<p>Ülke: ${country}</p>
<p>Posta kodu :${postcode}</p>
<p>Bölge:${province}</p>
`;
});
}
function onError(error)
{
if(error.code==1)
{
alert("kullanici erişim iznini reddeti");
}
else if( error.code==2)
{
alert("konum alinamadi");
}
else{
alert("bir hata oluştu");
}
}
let map;
function initMap()
{
map= new google.maps.Map(document.getElementById("map"),{
center:{lat:latitude,lng:longitude},
zoom:8,
});
const marker= new google.maps.Marker({
position:{lat:latitude,lng:longitude},
map:map,
});
}
//ben html ve css için google cloud platformdan bir api almam ve bunum içinde orada proje açmam gerek.