-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
57 lines (55 loc) · 1.26 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 Geolocation</title>
<style>
body {
margin: 0;
text-align: center;
}
#map {
margin-top: 20px;
width: 400px;
height: 400px;
background-color: #f9f9f9;
display: none;
}
</style>
</head>
<body>
<h1>HTML5 Geolocation</h1>
<p>Tekan tombol di bawah untuk mendeteksi lokasi Kamu</p>
<div>
<button id="detect">Dapatkan Lokasi</button>
</div>
<div id="map"></div>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkE6oJvsyX4sRAw0QTt3R_gJClY0NtIFQ"></script>
<script src="gmaps.js"></script>
<script>
document.getElementById("detect").addEventListener("click", () => {
if("geolocation" in navigator) {
document.getElementById("map").style.display = "inline-block";
setTimeout(function() {
navigator.geolocation.getCurrentPosition((result) => {
var position = {
lat: result.coords.latitude,
lng: result.coords.longitude
}
var map = new GMaps({
div: '#map',
lat: position.lat,
lng: position.lng
});
map.addMarker({
position: position
})
});
}, 250);
}else{
console.error("Geolocation tidak tersedia pada browser kamu.")
}
});
</script>
</body>
</html>