-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.html
More file actions
91 lines (87 loc) · 3.34 KB
/
map.html
File metadata and controls
91 lines (87 loc) · 3.34 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<style>
body {
font-family: sans-serif;
}
.map-layer {
height: 100%;
width: 100%;
}
</style>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<h1>View current location</h1>
<p><a href="index.html">Back to login</a></p><br>
<div class="map-layer" id="map-layer"></div>
</html>
<script type="text/javascript">
let map;
let feedback = "TEST";
let currentLatitude = 0.0;
let currentLongitude = 0.0;
let centerCoordinates = {
lat: currentLatitude,
lng: currentLongitude
};
let currentLocation = {
lat: 0.0,
lng: 0.0,
IP: "default"
}
function initMap() {
$.get("https://ipinfo.io", function(response) {
//alert(response.ip);
feedback = response.ip;
}, "json")
updateLocation();
let mapLayer = document.getElementById("map-layer");
//let centerCoordinates = new google.maps.LatLng(currentLatitude, currentLongitude);
let defaultOptions = {
center: centerCoordinates,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 25
}
map = new google.maps.Map(mapLayer, defaultOptions);
let marker = new google.maps.Marker({
position: centerCoordinates,
map: map
});
marker.setMap(map);
google.maps.event.addListener(marker, 'click', function() {
infoWindow.open(map, marker);
});
marker.setPosition(currentLocation);
map.setCenter(currentLocation);
}
function updateLocation() {
if ("geolocation" in navigator){
navigator.geolocation.getCurrentPosition(function(position){
currentLatitude = position.coords.latitude;
currentLongitude = position.coords.longitude;
centerCoordinates = {
lat: currentLatitude,
lng: currentLongitude
};
let infoWindowHTML = "Latitude: " + currentLatitude + "<br>Longitude: " + currentLongitude + "<br>IP: " + feedback;
let infoWindow = new google.maps.InfoWindow({
map: map,
content: infoWindowHTML
});
currentLocation = {
lat: currentLatitude,
lng: currentLongitude,
IP: JSON.stringify(feedback)
};
infoWindow.setPosition(currentLocation);
});
} else {
alert("Permission denied!");
}
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCoh5mk6Q4LCq-EIC6GbuIusljgc7tVGQc&callback=initMap"
async defer></script>