forked from pvarshney1729/Summer-of-Code-18
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmap2.html
211 lines (171 loc) · 5.2 KB
/
map2.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html>
<head>
<title>First Page</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#floating-panel {
position: absolute;
top: 10px;
left: 28%;
z-index: 5;
background-color: #fff;
padding: 0px;
border: 1px solid #999;
text-align: center;
font-family: 'Roboto','sans-serif';
line-height: 30px;
padding-left: 0px;
}
button{
height="500px";
width=30%;
}
</style>
</head>
<body>
<div id="floating-panel">
<input onclick="deleteMarkers();" type=button value="Delete Markers">
<button onclick="showPosition();">Current Location</button>
<input type="text">
<input type=submit value="Submit">
</div>
<div id="map" style="width:100%;height:500px;"></div>
<div id="profile" style="width:100%;height:500px;background-color:cyan">
<p id="demo"></p>
<!--<table>
<tr>
<td><button class="button button1">UPDATE PROFILE</button></td>
<td><input type="button" value="COMPLAINT PROFILE"></td>
<td><input type="button" value="SIGNOUT"></td>
</tr>
</table>-->
<form>
lattitude: <input type="text" id="t1"><br>
longitute: <input type="text" id="t2"><br>
Name: <input type="text" id="t3"><br>
<textarea name="txt"></textarea><br>
<input type="button" onclick="myclick();" value="GIIVEN POINT">
</form>
</div>
<script type="text/javascript">
var map;
var markers = [];
var flag=0;
var x = document.getElementById("demo");
function myMap() {
var mapCanvas = document.getElementById("map");
var myCenter=new google.maps.LatLng(28.7041,77.1025);
var mapOptions = {center: myCenter, zoom: 5};
var map = new google.maps.Map(mapCanvas, mapOptions);
google.maps.event.addListener(map, 'click', function(event) {
if(flag==0){
flag=1;
placeMarker(map, event.latLng);
}
});
}
function placeMarker(map, location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
document.getElementById("t1").value=location.lat();
document.getElementById("t2").value=location.lng();
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow.open(map,marker);
markers.push(marker);
}
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
function deleteMarkers() {
setMapOnAll(null);
flag=0;
markers = [];
}
function showPosition(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showMap, showError);
} else{
alert("Sorry, your browser does not support HTML5 geolocation.");
}
}
// Define callback function for successful attempt
function showMap(position){
// Get location data
lat = position.coords.latitude;
long = position.coords.longitude;
var latlong = new google.maps.LatLng(lat, long);
document.getElementById("t1").value=lat;
document.getElementById("t2").value=long;
var myOptions = {
center: latlong,
zoom: 16,
mapTypeControl: true,
navigationControlOptions: {style:google.maps.NavigationControlStyle.SMALL}
}
var map = new google.maps.Map(document.getElementById("map"), myOptions);
google.maps.event.addListener(map, 'click', function(event) {
if(flag==0){
flag=1;
placeMarker(map, event.latLng);
}
});
if(flag==0){
flag=1;
placeMarker(map, latlong);
}
function placeMarker(map, location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow.open(map,marker);
markers.push(marker);
flag=1;
}
}
// Define callback function for failed attempt
function showError(error){
if(error.code == 1){
result.innerHTML = "You've decided not to share your position, but it's OK. We won't ask you again.";
} else if(error.code == 2){
result.innerHTML = "The network is down or the positioning service can't be reached.";
} else if(error.code == 3){
result.innerHTML = "The attempt timed out before it could get the location data.";
} else{
result.innerHTML = "Geolocation failed due to unknown error.";
}
}
function myclick() {
var lat = document.getElementById("t1").value;
var long = document.getElementById("t2").value;
var Center = new google.maps.LatLng(lat,long);
var mapCanvas = document.getElementById("map");
var mapOptions = {center: Center, zoom: 5};
var map = new google.maps.Map(mapCanvas, mapOptions);
var marker = new google.maps.Marker({position:Center});
marker.setMap(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC4qG7WIi9ajrdWEJRZVYZLeV3YcrjEdg8&callback=myMap"></script>
</body>
</html>