Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean code #4

Open
wants to merge 1 commit into
base: user-admin
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 85 additions & 85 deletions my_modules/firebaseUpload.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
var config = {
apiKey: "AIzaSyDqcidTNKiWrY_n2rl-J8xpoLBetUY0IiM",
authDomain: "g-mapster-1482049698790.firebaseapp.com",
databaseURL: "https://g-mapster-1482049698790.firebaseio.com",
storageBucket: "g-mapster-1482049698790.appspot.com",
messagingSenderId: "392450380738"
};
apiKey: "",
authDomain: "",
databaseURL: "",
storageBucket: "",
messagingSenderId: ""
};

firebase.initializeApp(config);
firebase.initializeApp(config);

//Get the upload button
const filebutton = document.querySelector('#pushbtn');
filebutton.addEventListener('change', function(e){
//Get the file
console.log('button clicked for file upload');
var file = e.target.files[0];
//Create storage refernce for it
var storageRef = firebase.storage().ref('g-mapster/' + file.name );
//Upload
var task = storageRef.put(file);
task.on('state_changed',
function progress(s){
var upload = s.bytesTransferred/s.totalBytes;
console.log(upload);
if(upload == 1){
var downloadURL = task.h.downloadURLs[0];
console.log(downloadURL);
saveGarbagePlace(downloadURL);
}
}
);
});

// Save the coordinates

function saveGarbagePlace(imageURL){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
console.log(position);
firebase.database().ref('/').push({
latitude : position.coords.latitude,
longitude : position.coords.longitude,
imageURL : imageURL
});
console.log('inserted');
markTheMap(position);
});
//Get the upload button
const filebutton = document.querySelector('#pushbtn');
filebutton.addEventListener('change', function (e) {
//Get the file
console.log('button clicked for file upload');
var file = e.target.files[0];
//Create storage refernce for it
var storageRef = firebase.storage().ref('g-mapster/' + file.name);
//Upload
var task = storageRef.put(file);
task.on('state_changed',
function progress(s) {
var upload = s.bytesTransferred / s.totalBytes;
console.log(upload);
if (upload == 1) {
var downloadURL = task.h.downloadURLs[0];
console.log(downloadURL);
saveGarbagePlace(downloadURL);
}
else
alert('Your device doesnt support geolocation');
}
);
});

// Mark the map
// Save the coordinates

function markTheMap(position){
console.log('markTheMap map');
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: { lat : position.coords.latitude-5, lng : position.coords.longitude-5 }
});
var ref = firebase.database().ref('/');
ref.orderByChild('latitude').on('child_added', function(snapshot){
console.log(snapshot.val().latitude);
console.log(snapshot.val().longitude);
var location = { lat : snapshot.val().latitude, lng : snapshot.val().longitude };
placeMarker(location, map);
});
}
function saveGarbagePlace(imageURL) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
console.log(position);
firebase.database().ref('/').push({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
imageURL: imageURL
});
console.log('inserted');
markTheMap(position);
});
}
else
alert('Your device doesnt support geolocation');
}

function placeMarker(location, map){
var marker = new google.maps.Marker({
position: location,
map: map,
icon : 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png',
title : 'Hello World!'
});
}
// Mark the map

function markTheMap(position) {
console.log('markTheMap map');
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: { lat: position.coords.latitude - 5, lng: position.coords.longitude - 5 }
});
var ref = firebase.database().ref('/');
ref.orderByChild('latitude').on('child_added', function (snapshot) {
console.log(snapshot.val().latitude);
console.log(snapshot.val().longitude);
var location = { lat: snapshot.val().latitude, lng: snapshot.val().longitude };
placeMarker(location, map);
});
}

function initMap(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: { lat : position.coords.latitude-5, lng : position.coords.longitude-5 }
});
var ref = firebase.database().ref('/');
ref.orderByChild('latitude').on('child_added', function(snapshot){
console.log(snapshot.val().latitude);
console.log(snapshot.val().longitude);
var location = { lat : snapshot.val().latitude, lng : snapshot.val().longitude };
placeMarker(location, map);
});
function placeMarker(location, map) {
var marker = new google.maps.Marker({
position: location,
map: map,
icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png',
title: 'Hello World!'
});
}

function initMap() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: { lat: position.coords.latitude - 5, lng: position.coords.longitude - 5 }
});
}
}
var ref = firebase.database().ref('/');
ref.orderByChild('latitude').on('child_added', function (snapshot) {
console.log(snapshot.val().latitude);
console.log(snapshot.val().longitude);
var location = { lat: snapshot.val().latitude, lng: snapshot.val().longitude };
placeMarker(location, map);
});
});
}
}