-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
297 lines (264 loc) · 9.25 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php session_start(); ?>
<!DOCTYPE xhtml PUBLIC "-//W3C//DTD XHTML 4.01//EN">
<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>Where Am I?</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<!--<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js"></script>-->
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="geometa.js"></script>
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<style type="text/css">
*, html { margin:0; padding:0 }
div#map_canvas { width:100%; height:100%; }
div#info { width:100%; position:absolute; overflow:hidden; text-align:center; top:0;
left:0; }
.lightBox {
filter:alpha(opacity=60);
-moz-opacity:0.6;
-khtml-opacity: 0.6;
opacity: 0.6;
background-color:white;
padding:2px;
}
div#info2 .lightBox2 {
padding:2px;
filter:alpha(opacity=100);
-moz-opacity:1;
-khtml-opacity: 1;
opacity: 1;
background-color:black;
padding:2px;
}
</style>
<script type="text/javascript">
var infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});
var map;
useremail = '';
function initialise() {
var latlng = new google.maps.LatLng(49 ,2);
var myOptions = {
zoom: 7,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: false
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
eviction_list = [];
windows = [];
loadMarkers();
}
function evictMarkers() {
// clear all markers
$(eviction_list).each(function () {
this.setMap(null);
});
// reset the eviction array
eviction_list = [];
}
function createMarker(latlng, name, html) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
});
// save the info we need to use later for the side_bar
eviction_list.push(marker);
}
function loadMarkers() {
// Download positions
downloadUrl("get.php", function(data) {
var markers = data.documentElement.getElementsByTagName("marker");
evictMarkers();
for (var i = 0; i < markers.length; i++) {
var latlng = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var titre = markers[i].getAttribute("user");
// Function : position, titre
var marker = createMarker(latlng, titre, titre + ' ' + latlng);
// var marker = new google.maps.Marker({position: latlng, map: map, name: markers[i].getAttribute("title"),clickable: true});
//
// var titre = markers[i].getAttribute("title");
// marker.titre = titre;
//// google.maps.event.addListener(marker, "click", function() {
// // if (infowindow) infowindow.close();
// // infowindow = new google.maps.InfoWindow({content: name});
// // infowindow.open(map, marker);
// //});
//
// eviction_list[i] = marker;
//
// windows[i] = new google.maps.InfoWindow({
// content: marker.titre
// });
//
// google.maps.event.addListener(eviction_list[i], 'click', function () {
// windows[i].open(map, eviction_list[i]);
// });
}
});
//Refresh every 5 seconds :
setTimeout(loadMarkers, 30000);
}
function doGeolocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(positionSuccess, positionError);
} else {
positionError(-1);
}
}
function positionError(err) {
var msg;
switch(err.code) {
case err.UNKNOWN_ERROR:
msg = "Unable to find your location";
break;
case err.PERMISSION_DENINED:
msg = "Permission denied in finding your location";
break;
case err.POSITION_UNAVAILABLE:
msg = "Your location is currently unknown";
break;
case err.BREAK:
msg = "Attempt to find location took too long";
break;
default:
msg = "Location detection not supported in browser";
}
document.getElementById('texte').innerHTML = msg;
}
function positionSuccess(position) {
// Centre the map on the new location
var coords = position.coords || position.coordinate || position;
var latLng = new google.maps.LatLng(coords.latitude, coords.longitude);
var dataString = 'user=' + document.getElementById('email').innerHTML + '&lat=' + coords.latitude + '&long=' + coords.longitude
$.ajax({
type: "POST",
url: "add.php",
data: dataString
});
map.setCenter(latLng);
map.setZoom(12);
var marker = new google.maps.Marker({
map: map,
position: latLng,
title: 'Why, there you are!'
});
document.getElementById('texte').innerHTML = 'Looking for <b>' +
coords.latitude + ', ' + coords.longitude + '</b>...';
// And reverse geocode.
(new google.maps.Geocoder()).geocode({latLng: latLng}, function(resp) {
var place = "You're around here somewhere!";
if (resp[0]) {
var bits = [];
for (var i = 0, I = resp[0].address_components.length; i < I; ++i) {
var component = resp[0].address_components[i];
if (contains(component.types, 'political')) {
bits.push('<b>' + component.long_name + '</b>');
}
}
if (bits.length) {
place = bits.join(' > ');
}
marker.setTitle(resp[0].formatted_address);
}
document.getElementById('texte').innerHTML = place + ' <input id="clickMe" type="button" value="Refresh my position" onclick=" doGeolocation();" />' ;
});
}
function contains(array, item) {
for (var i = 0, I = array.length; i < I; ++i) {
if (array[i] == item) return true;
}
return false;
}
/*
* Triggered when the user accepts the the sign in, cancels, or closes the
* authorization dialog.
*/
function loginFinishedCallback(authResult) {
if (authResult) {
if (authResult['error'] == undefined){
gapi.auth.setToken(authResult); // Store the returned token.
toggleElement('signin-button'); // Hide the sign-in button after successfully signing in the user.
getEmail(); // Trigger request to get the email address.
} else {
console.log('An error occurred');
}
} else {
console.log('Empty authResult'); // Something went wrong
}
}
/*
* Initiates the request to the userinfo endpoint to get the user's email
* address. This function relies on the gapi.auth.setToken containing a valid
* OAuth access token.
*
* When the request completes, the getEmailCallback is triggered and passed
* the result of the request.
*/
function getEmail(){
// Load the oauth2 libraries to enable the userinfo methods.
gapi.client.load('oauth2', 'v2', function() {
var request = gapi.client.oauth2.userinfo.get();
request.execute(getEmailCallback);
});
}
function getEmailCallback(obj){
var el = document.getElementById('email');
var email = '';
if (obj['email']) {
email = obj['email'];
useremail = email;
}
console.log(obj); // Uncomment to inspect the full object.
el.innerHTML = email;
toggleElement('email');
prepareGeolocation();
doGeolocation();
}
function toggleElement(id) {
var el = document.getElementById(id);
if (el.getAttribute('class') == 'hide') {
el.setAttribute('class', 'show');
} else {
el.setAttribute('class', 'hide');
}
}
</script>
<style type="text/css">
.hide { display: none;}
.show { display: block;}
</style>
<script src="https://apis.google.com/js/plusone.js" type="text/javascript"></script>
</head>
<body onload="initialise()">
<div id="map_canvas"></div>
<div id="info" class="lightbox"><div id="texte">Log in to sync your location...</div><div id="email" class="hide"></div>
<div id="signin-button" class="show">
<div class="g-signin" data-callback="loginFinishedCallback"
data-clientid="162643658826.apps.googleusercontent.com"
data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email"
data-height="short"
data-cookiepolicy="single_host_origin"
>
</div></div>
<div id="info2" class="lightbox2" align="right">
<span><a href="http://rlier.fr/geomap2/login_with_google.php">test</a></span>
<span><a onclick="androidlogin();">test2</a></span>
<input id="clickMe" type="image" style="height:40px;width:40px;" src="./refresh.png" onclick=" androidlogin();" />
<input id="clickMe" type="image" style="height:40px;width:40px;" src="./refresh.png" onclick=" doGeolocation();" />
<input id="clickMe" type="image" style="height:40px;width:40px;" src="./Centermap.png" onclick=" doGeolocation();" />
</div></div>
</body>
</html>