-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
60 lines (52 loc) · 1.79 KB
/
script.js
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
// Initialize Firebase
var config = {
apiKey: "AIzaSyAyo1ZF-MNzpUF0pHPfDgVhYNRGHt8RV58",
authDomain: "open-ahmedabad.firebaseapp.com",
databaseURL: "https://open-ahmedabad.firebaseio.com",
storageBucket: "open-ahmedabad.appspot.com",
messagingSenderId: "140801138096"
};
firebase.initializeApp(config);
var database = firebase.database();
var inputLatitudeDOM = document.getElementById("inputLatitude");
var inputLongitudeDOM = document.getElementById("inputLongitude");
var inputNameDOM = document.getElementById("inputName");
var inputAddressDOM = document.getElementById("inputAddress");
var inputFeesDOM = document.getElementById("inputFees");
var inputRatingDOM = document.getElementById("inputRating");
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(showPosition, function(error){
alert(error.message);
}, {
enableHighAccuracy: true
,timeout : 5000
});
function submitData() {
var lat = inputLatitudeDOM.value;
var long = inputLongitudeDOM.value;
var name = inputNameDOM.value;
var address = inputAddressDOM.value;
var fees = inputFeesDOM.value;
var rating = inputRatingDOM.value;
database.ref('loo/' + uuid()).set({
latitude: lat,
longitude: long,
name: name,
address: address,
fees: fees,
cleanliness: rating
});
}
function showPosition(position) {
inputLatitudeDOM.value = position.coords.latitude;
inputLongitudeDOM.value = position.coords.longitude;
}
function uuid(){
var d = new Date().getTime();
var uid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
});
return uid;
}