-
Notifications
You must be signed in to change notification settings - Fork 0
/
Currentlocation.html
78 lines (63 loc) · 1.78 KB
/
Currentlocation.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
#map {
height: 500px;
width: 100%;
}
</style>
</head>
<body>
<h1>My Current Location</h1>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: -34.397, lng: 150.644 },
zoom: 13
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var marker = new google.maps.Marker({
position: pos,
icon: 'flag.png',
map: map, animation: google.maps.Animation.BOUNCE
});
var infowindow = new google.maps.InfoWindow({
content: 'Location Found!<br> ' + 'Latitude: ' + position.coords.latitude + '<br>Longitude: ' + position.coords.longitude
});
infowindow.open(map, marker);
}, function () {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infoWindow.open(map);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=(YOURAPIKEY)&callback=initMap">
</script>
<p align='left'>
<b>
Note: Please click "Allow" button in pop up message.
</b>
</p>
</body>
</html>