-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo_alert.html
executable file
·112 lines (97 loc) · 3.31 KB
/
repo_alert.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html >
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>From Info Windows to a Database: Saving User-Added Form Data</title>
<style>
#map {
height: 100vh;
width: 100%;
background-color: grey;
/*padding: 10px;*/
align-content: center;
/*margin-left: 10%;*/
}
</style>
</head>
<body>
<div id="map"></div>
<div id="form">
<table>
<tr><td>Disease:</td> <td><input type='text' id='name'/> </td> </tr>
<tr><td>Description:</td> <td><input type='text' id='des'/> </td> </tr>
<tr><td>No of cases:</td><td><input type="text" id="cases"></td></tr>
<tr><td></td><td><input type='button' value='Save' onclick='saveData()'/></td></tr>
</table>
</div>
<div id="message">Location saved</div>
<script>
var map;
var marker;
var infowindow;
var messagewindow;
var x = document.getElementById('form');
x.style.display = "none";
var y = document.getElementById('message');
y.style.display ="none";
function initMap() {
var origin = {lat: 19, lng: 72};
map = new google.maps.Map(document.getElementById('map'), {
center: origin,
zoom: 4
});
infowindow = new google.maps.InfoWindow({
content: x
});
messagewindow = new google.maps.InfoWindow({
content: y
});
google.maps.event.addListener(map, 'click', function(event) {
marker = new google.maps.Marker({
position: event.latLng,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
x.style.display = "block";
infowindow.open(map, marker);
});
});
}
function saveData() {
var name = escape(document.getElementById('name').value);
var des = escape(document.getElementById('des').value);
var cases = escape(document.getElementById('cases').value);
var latlng = marker.getPosition();
var url = 'phpsqlinfo_addrow.php?name=' + name + '&des=' + des +
'&lat=' + latlng.lat() + '&lng=' + latlng.lng() + '&cases=' + cases;
downloadUrl(url, function(data, responseCode) {
if (true /*responseCode == 200 && data.length <= 1*/) {
console.log(data);
infowindow.close();
marker.setMap(null);
y.style.display="block";
messagewindow.open(map, marker);
}
});
}
function downloadUrl(url, callback) {
var request = new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 1) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
console.log(request.readyState);
request.open("GET", url, true);
request.send();
console.log(request.readyState);
}
function doNothing () {
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBOjj5yR_uy57jVp0u9moK2SJbtd756swk&callback=initMap">
</script>
</body>
</html>