From 817cc94a3fb178d03097f953d1319b36df1a8a1f Mon Sep 17 00:00:00 2001 From: Jorge Sierra <3d.jorgesierra@gmail.com> Date: Sun, 24 Mar 2019 08:18:51 -0400 Subject: [PATCH 1/8] initial commit --- assets/javascript/Geofire.js | 0 assets/javascript/main.js | 83 +++++++++++++++++++++++++++++++--- assets/javascript/main_edua.js | 81 --------------------------------- index.html | 65 +++----------------------- 4 files changed, 83 insertions(+), 146 deletions(-) create mode 100644 assets/javascript/Geofire.js delete mode 100644 assets/javascript/main_edua.js diff --git a/assets/javascript/Geofire.js b/assets/javascript/Geofire.js new file mode 100644 index 0000000..e69de29 diff --git a/assets/javascript/main.js b/assets/javascript/main.js index ef83203..eb99ed8 100644 --- a/assets/javascript/main.js +++ b/assets/javascript/main.js @@ -23,15 +23,16 @@ function getGeoLocation() { var pLocation = $("

"); pLocation.text("The Lattitude-array: " + userLocation[0] + " and the longitude-array: " + userLocation[1]); + //update maps + googleMapsLoad(userLocation[0], userLocation[1]); + + //update body $("body").append(pLocation); - }); + }); } else { console.log("no access to geto") } - console.log("console lat - " + userLocation[0] + " console long - " + userLocation[1]); - - // this is the call for YELP QUERY - WORKING var yelpQuery = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=delis&latitude=39.951061&longitude=-75.165619&radius=8000"; @@ -48,12 +49,82 @@ function getGeoLocation() { }, method: "GET" }).then((yelpResponse) => { - console.log(yelpResponse); - } + console.log(yelpResponse); + } ); } +//google map function of generating user and icon +function googleMapsLoad(userLat, userLng) { + + // initialize maps + + var map = new google.maps.Map(document.getElementById("map"), { + zoom: 20, + center: { + lat: userLat, + lng: userLng + } + }); + + var allUsers = [ + + firstUser = { + coords: { + lat: userLat, + lng: userLng, + radius: 10 + }, + iconImage: "./assets/images/map-icon.png", + content: "

Hello Friends!

" + } + + ] + + console.log(allUsers); + //loop through markers + for (var i = 0; i < allUsers.length; i++) { + addUserMarker(allUsers[i]); + } + + + //function Marker + function addUserMarker(user) { + //Add marker + var marker = new google.maps.Marker({ + position: user.coords, + map: map, + + }); + + console.log(user.coords); + + //if user has an Icon + if (user.iconImage) { + //set Icon image + marker.setIcon(user.iconImage); + } + + // if it contains infoWindow text then create one + if (user.content) { + + //infoWindow is a pop up for the onClick + var infoWindow = new google.maps.InfoWindow({ + content: user.content + }); + + } + + marker.addListener("click", () => { + + infoWindow.open(map, marker); + }); + + } +} + + $(document).on("click", "#getGeoLocation", getGeoLocation); //firebase Google Maps API diff --git a/assets/javascript/main_edua.js b/assets/javascript/main_edua.js deleted file mode 100644 index 9a8e99c..0000000 --- a/assets/javascript/main_edua.js +++ /dev/null @@ -1,81 +0,0 @@ -//https://api.yelp.com/v3/businesses/search -// GET https://api.yelp.com/v3/autocomplete?text=del&latitude=37.786882&longitude=-122.399972 -//https://cors-anywhere.herokuapp.com/ - -//Global variables -var userLocation = new Array(0,0); -var gMap; - -// var googleMapQuery = "https://maps.googleapis.com/maps/api/js?key=AIzaSyA4Xg_9AqzPbXG547Ie66bFn-kqaYduOe0" > - -// Just using HTML API for geo location and test it with other APIs -function getGeoLocation() { - - /*var userLocation = { - lat: 0, - lng: 0 - }*/ - console.log("navigator.geolocation: " + navigator.geolocation); - if(navigator.geolocation) { - navigator.geolocation.getCurrentPosition((position) => { //This function appears to run asynchronos...see notes - - //Push Latitude and Longitude - //userLocation.push(position.coords.latitude); - //userLocation.push(position.coords.longitude); - - userLocation[0] = position.coords.latitude; - userLocation[1] = position.coords.longitude; - - //display lattitude and longitude in dom - var pLocation = $("

"); - - //Note 1: This output doesn't show until I accept "Allow Location" - pLocation.text("The Lattitude-array: " + userLocation[0] + " and the longitude-array: " + userLocation[1]); - - $("body").append(pLocation); - - } ); - } else { - console.log("no access to geto") - } - - //Note 2: This output shows up right after I press the button - console.log("console lat - " + userLocation[0] + " console long - " + userLocation[1]); - - //Note 3: Conclusion: The function declares the variables ONLY when the "Allow location" is accpected. Otherwise, the variable is undefined - // You were leaning this way but it's important to know (I believe) that the part where the location data is gathered is asynchronos to the line at 43. - // Which is to say that you will get the output of the console log before the location value actually set. - -// this is the call for YELP QUERY -// var yelpQuery = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=delis&latitude=39.951061&longitude=-75.165619&radius=8046.72"; -//testing to see if I can get variables included - - var yelpQuery = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=delis&latitude=" + userLocation[0] + "&longitude=" + userLocation[1] + "&radius=8000"; - var yelpAPI = "1QpSc4B1zI5GuI56PDAAvAfpfcsLg9LWuHRfVCeG4TIDDxRe3hGT-sxlU5h5DD0AdLgu-HHoa2cM4m1WaAefYoboIPdVHv0mCjivrwQrdU11FCFl2hd8-iaaTKOTXHYx"; - - - console.log(yelpQuery); - $.ajax({ - url: yelpQuery, - headers: { - 'Authorization': "Bearer " + yelpAPI, - }, - method: "GET" - }).then((yelpResponse) => { - console.log(yelpResponse); - } - - ); -} - -$(document).on("click", "#getGeoLocation", getGeoLocation); - -// getGeoLocation(); - - - -//firebase Google Maps API -//https://www.google.com/maps/embed/v1/MODE?key=AIzaSyCHREkl-BVxFLXW5Hp_reWCSnIDK-Oq2Wk¶meters - - -// Execute functions \ No newline at end of file diff --git a/index.html b/index.html index 9fcfb00..eef3e96 100644 --- a/index.html +++ b/index.html @@ -26,74 +26,20 @@

Google Map

function initMap() { //fixed place for now var place = { - zoom: 18, + zoom: 10, center: { - lat: 42, - lng: -71 + lat: 39.94, + lng: -75.1993 } } //new map var map = new google.maps.Map(document.getElementById("map"), place); + console.log(map); //Array of Users - var allUsers = [ - - firstUser = { - coords: { - lat: 42, - lng: -71 - }, - iconImage: "./assets/images/map-icon.png", - content: "

Hello Friends!

" - } - - ] - - console.log(allUsers); - //loop through markers - for (var i = 0; i < allUsers.length; i++) { - addUserMarker(allUsers[i]); - } - - - //function Marker - function addUserMarker(user) { - //Add marker - var marker = new google.maps.Marker({ - position: user.coords, - map: map, - - }); - - console.log(user.coords); - - //if user has an Icon - if (user.iconImage) { - //set Icon image - marker.setIcon(user.iconImage); - } - - // if it contains infoWindow text then create one - if (user.content) { - - //infoWindow is a pop up for the onClick - var infoWindow = new google.maps.InfoWindow({ - content: user.content - }); - - } - - marker.addListener("click", () => { - - infoWindow.open(map, marker); - }); - - } - - - } + + From 2ca198b5c09d5c4ab07622434533688a4fd35784 Mon Sep 17 00:00:00 2001 From: Jorge <3d.jorgesierra@gmail.com> Date: Sun, 24 Mar 2019 15:34:08 -0400 Subject: [PATCH 2/8] Still need to work on geoQuery --- assets/javascript/Geofire.1.js | 47 ++++++++ assets/javascript/Geofire.js | 0 assets/javascript/geoTest.js | 50 +++++++++ assets/javascript/geofire.min.js | 1 + assets/javascript/main.js | 179 +++++++++++++++++++++++++------ index.html | 30 ++++-- 6 files changed, 264 insertions(+), 43 deletions(-) create mode 100644 assets/javascript/Geofire.1.js delete mode 100644 assets/javascript/Geofire.js create mode 100644 assets/javascript/geoTest.js create mode 100644 assets/javascript/geofire.min.js diff --git a/assets/javascript/Geofire.1.js b/assets/javascript/Geofire.1.js new file mode 100644 index 0000000..2e39d9e --- /dev/null +++ b/assets/javascript/Geofire.1.js @@ -0,0 +1,47 @@ + // Initialize Firebase + var config = { + apiKey: "AIzaSyBWlRO86vNl6sL5psQX5f7H9Lw_wsULP9g", + authDomain: "geofiretest-9d07e.firebaseapp.com", + databaseURL: "https://geofiretest-9d07e.firebaseio.com", + projectId: "geofiretest-9d07e", + storageBucket: "geofiretest-9d07e.appspot.com", + messagingSenderId: "680094207901" + }; + firebase.initializeApp(config); + + //variables for firebase database + var firebaseData = firebase.database(); +// geofire ref +var firebaseRef = firebase.database().ref().push(); + var geoFire = new GeoFire(firebaseRef); + + //setting initial location + geoFire.set("user_key", [37.785326, -122.405696]).then(function (){ + console.log("provided key has been added to Geofire"); + }, function (error){ + console.log("error: " + error); + }); + + //getting initial location + geoFire.get("user_key").then(function(location) { + if (location === null) { + console.log("Provided key is not in GeoFire"); + } + else { + console.log("Provided key has a location of " + location); + } + }, function(error) { + console.log("Error: " + error); + }); + + //setup a query that looks at the user's location. + var geoQuery = geoFire.geoQuery({ + center: [37.4, -122.6], + radius: 1.609 //kilometers + }); + + //check to see if anything has entered this location + geoQuery.on("key_entered", function(key, location, distance) { + console.log("Bicycle shop " + key + " found at " + location + " (" + distance + " km away)"); + }); + diff --git a/assets/javascript/Geofire.js b/assets/javascript/Geofire.js deleted file mode 100644 index e69de29..0000000 diff --git a/assets/javascript/geoTest.js b/assets/javascript/geoTest.js new file mode 100644 index 0000000..9a33f6a --- /dev/null +++ b/assets/javascript/geoTest.js @@ -0,0 +1,50 @@ + // Initialize Firebase + var config = { + apiKey: "AIzaSyBWlRO86vNl6sL5psQX5f7H9Lw_wsULP9g", + authDomain: "geofiretest-9d07e.firebaseapp.com", + databaseURL: "https://geofiretest-9d07e.firebaseio.com", + projectId: "geofiretest-9d07e", + storageBucket: "geofiretest-9d07e.appspot.com", + messagingSenderId: "680094207901" +}; +firebase.initializeApp(config); + +//variables for firebase database +var firebaseData = firebase.database(); +// geofire ref +var firebaseRefPush = firebase.database().ref().push(); + +var geoFire = new GeoFire(firebaseRefPush); +console.log("firebase "+ geoFire); + +//setting initial location +geoFire.set("user_key", [37.785326, -122.405696]).then(function (){ + console.log("provided key has been added to Geofire"); +}, function (error){ + console.log("error: " + error); +}); + + +//getting initial location +geoFire.get("user_key").then(function(location) { + if (location === null) { + console.log("Provided key is not in GeoFire"); + } + else { + console.log("Provided key has a location of " + location); + } +}, function(error) { + console.log("Error: " + error); +}); + +//setup a query that looks at the user's location. +var geoQuery = geoFire.query({ + center: [37.4, -122.6], + radius: 1.609 //kilometers +}); + +//check to see if anything has entered this location +geoQuery.on("key_entered", function(key, location, distance) { + console.log("Bicycle shop " + key + " found at " + location + " (" + distance + " km away)"); +}); + diff --git a/assets/javascript/geofire.min.js b/assets/javascript/geofire.min.js new file mode 100644 index 0000000..c08b8e2 --- /dev/null +++ b/assets/javascript/geofire.min.js @@ -0,0 +1 @@ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).geofire={})}(this,function(e){"use strict";var t=function(){function e(e){if(this._cancelCallback=e,"[object Function]"!==Object.prototype.toString.call(this._cancelCallback))throw new Error("callback must be a function")}return e.prototype.cancel=function(){void 0!==this._cancelCallback&&(this._cancelCallback(),this._cancelCallback=void 0)},e}(),l=10,f="0123456789bcdefghjkmnpqrstuvwxyz",h=40007860,_=110574,y=5,u=22*y,i=6378137,a=.00669447819799,o=1e-12;function d(e){return Math.log(e)/Math.log(2)}function s(e){var t;if("string"!=typeof e?t="key must be a string":0===e.length?t="key cannot be the empty string":755<1+l+e.length?t="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(t="key cannot contain any of the following characters: . # $ ] [ /"),void 0!==t)throw new Error("Invalid GeoFire key '"+e+"': "+t)}function v(e){var t;if(Array.isArray(e))if(2!==e.length)t="expected array of length 2, got length "+e.length;else{var r=e[0],n=e[1];"number"!=typeof r||isNaN(r)?t="latitude must be a number":r<-90||90>o<=i[0]&&e<=i[1])return!0}}return!1},e.prototype._geohashQueryReadyCallback=function(e){var t=this._outstandingGeohashReadyEvents.indexOf(e);-1 +// Initialize Firebase +var config = { + apiKey: "AIzaSyBWlRO86vNl6sL5psQX5f7H9Lw_wsULP9g", + authDomain: "geofiretest-9d07e.firebaseapp.com", + databaseURL: "https://geofiretest-9d07e.firebaseio.com", + projectId: "geofiretest-9d07e", + storageBucket: "geofiretest-9d07e.appspot.com", + messagingSenderId: "680094207901" +}; +firebase.initializeApp(config); + +//firebase database +var firebaseData = firebase.database(); +var firebaseUserLocation = firebaseData.ref("firebase location"); +// geofire ref +var geoFireRefPush = firebase.database().ref("/geofire-location").push(); +// gefire initilize +var geoFire = new GeoFire(geoFireRefPush); +//-------- // Just using HTML API for geo location and test it with other APIs function getGeoLocation() { userLocation = []; - + var firebaseKey = Object.key; // place inside function then query for it. if (navigator.geolocation) { navigator.geolocation.getCurrentPosition((position) => { @@ -23,14 +39,71 @@ function getGeoLocation() { var pLocation = $("

"); pLocation.text("The Lattitude-array: " + userLocation[0] + " and the longitude-array: " + userLocation[1]); - //update maps - googleMapsLoad(userLocation[0], userLocation[1]); + + //Set user's info for fireBasae + var userInfo = [ + user1 = { + name: "Jorge", + center: { + lat: parseFloat(userLocation[0]), + lng: parseFloat(userLocation[1]) + }, + radius: 5 //kilometers + }, + user2 = { + name: "user 2", + center: { + lat: parseFloat(40.065494), + lng: parseFloat(-75.091064) + }, + radius: 5 //kilometers + } + ] + + + //update map with location of user and create an icon and circle. + googleMapShout(userLocation[0], userLocation[1]); + + //set the user location to firebase + firebaseUserLocation.set(userInfo); + + //geofire set location + firebaseUserLocation.once("value").then(setGeoFireUserInfo, errorObject); + + //user who pressed the shout set geoQuery + + var shoutQuery = geoFire.query({ + center: userLocation, + radius: 5 // kilometers + }); + + // look at other people around + var peopleAround = { + name: "user 2", + center: { + lat: parseFloat(40.065494), + lng: parseFloat(-75.091064) + }, + radius: 5 //kilometers + }; + + //check if someone is in your radius + shoutQuery.on("key_entered", function (key, location, distance) { + peopleAround = { + id: key, + distance: distance, + location: location + }; + // addSellerToMap(oneSeller); + console.log("People Around: " + peopleAround); + }); + //update body $("body").append(pLocation); - }); + }); } else { - console.log("no access to geto") + console.log("no access to geto"); } // this is the call for YELP QUERY - WORKING @@ -40,44 +113,58 @@ function getGeoLocation() { // var yelpQuery = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=delis&latitude=" + userLocation[0] + "&longitude=" + userLocation[1] + "&radius=8000"; var yelpAPI = "1QpSc4B1zI5GuI56PDAAvAfpfcsLg9LWuHRfVCeG4TIDDxRe3hGT-sxlU5h5DD0AdLgu-HHoa2cM4m1WaAefYoboIPdVHv0mCjivrwQrdU11FCFl2hd8-iaaTKOTXHYx"; + // //-----------YELP CALL + // $.ajax({ + // url: yelpQuery, + // headers: { + // 'Authorization': "Bearer " + yelpAPI, + // }, + // method: "GET" + // }).then((yelpResponse) => { + // console.log("Yelp response: "+ yelpResponse); + // } + + // ); +} - console.log(yelpQuery); - $.ajax({ - url: yelpQuery, - headers: { - 'Authorization': "Bearer " + yelpAPI, - }, - method: "GET" - }).then((yelpResponse) => { - console.log(yelpResponse); - } - ); -} //google map function of generating user and icon -function googleMapsLoad(userLat, userLng) { +function googleMapShout(userLat, userLng) { // initialize maps var map = new google.maps.Map(document.getElementById("map"), { - zoom: 20, + zoom: 11, center: { lat: userLat, lng: userLng } }); + var allUsers = [ firstUser = { coords: { - lat: userLat, - lng: userLng, - radius: 10 + center: { + lat: userLat, + lng: userLng + }, + radius: 5 //kilometers }, iconImage: "./assets/images/map-icon.png", content: "

Hello Friends!

" + }, + + secondPerson = { + coords: { + center: { + lat: 40.065445, + lng: -75.090635 + } + + } } ] @@ -93,12 +180,11 @@ function googleMapsLoad(userLat, userLng) { function addUserMarker(user) { //Add marker var marker = new google.maps.Marker({ - position: user.coords, - map: map, - + position: user.coords.center, + map: map }); - console.log(user.coords); + console.log(user.coords.center); //if user has an Icon if (user.iconImage) { @@ -121,14 +207,41 @@ function googleMapsLoad(userLat, userLng) { infoWindow.open(map, marker); }); + var cityCircle = new google.maps.Circle({ + strokeColor: '#FF0000', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#FF0000', + fillOpacity: 0.35, + map: map, + center: user.coords.center, + radius: (user.coords.radius) * 1000 //kilometers + }); + console.log(user.coords.radius); } } +function setGeoFireUserInfo(snapshot) { + //get snapshot vallue + var snapshot = snapshot.val(); + // var keys = Object.keys(snapshot); + //add all users + for (var i = 0; i < snapshot.length; i++) { + var userName = snapshot[i].name; + var userLocation = [snapshot[i].center.lat, snapshot[i].center.lng]; + var userRadius = snapshot[i].radius; -$(document).on("click", "#getGeoLocation", getGeoLocation); + geoFire.set(userName, userLocation).then(function () { + console.log("Current user " + userName + "'s location has been added to GeoFire and your location is " + userLocation); -//firebase Google Maps API -//https://www.google.com/maps/embed/v1/MODE?key=AIzaSyCHREkl-BVxFLXW5Hp_reWCSnIDK-Oq2Wk¶meters + // geoFireRefPush.child(userName).onDisconnect().remove(); + }); + } +} +function errorObject(errorObject) { + console.log("The read failed: " + errorObject.code); +}; -// Execute functions \ No newline at end of file +// Execute functions +$(document).on("click", "#getGeoLocation", getGeoLocation); \ No newline at end of file diff --git a/index.html b/index.html index eef3e96..932c14a 100644 --- a/index.html +++ b/index.html @@ -5,8 +5,20 @@ + Shout! + + + + + + + + + + + @@ -16,7 +28,7 @@

Google Map

- +
@@ -24,7 +36,7 @@

Google Map

- - - - + + - + From 8b8e287e706dd319205a207571b36409a16b02da Mon Sep 17 00:00:00 2001 From: Jorge <3d.jorgesierra@gmail.com> Date: Sun, 24 Mar 2019 20:59:28 -0400 Subject: [PATCH 3/8] Working distance checker --- assets/javascript/main.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/assets/javascript/main.js b/assets/javascript/main.js index f11ed85..0c2cad7 100644 --- a/assets/javascript/main.js +++ b/assets/javascript/main.js @@ -2,6 +2,7 @@ var userLocation = []; var gMap; + // Initialize Firebase var config = { apiKey: "AIzaSyBWlRO86vNl6sL5psQX5f7H9Lw_wsULP9g", @@ -21,6 +22,8 @@ var geoFireRefPush = firebase.database().ref("/geofire-location").push(); // gefire initilize var geoFire = new GeoFire(geoFireRefPush); //-------- +// geoquery +var shoutQuery; // Just using HTML API for geo location and test it with other APIs function getGeoLocation() { @@ -64,12 +67,12 @@ function getGeoLocation() { //update map with location of user and create an icon and circle. googleMapShout(userLocation[0], userLocation[1]); + //geofire set location + firebaseUserLocation.on("value", setGeoFireUserInfo, errorObject); + //set the user location to firebase firebaseUserLocation.set(userInfo); - //geofire set location - firebaseUserLocation.once("value").then(setGeoFireUserInfo, errorObject); - //user who pressed the shout set geoQuery var shoutQuery = geoFire.query({ @@ -95,10 +98,10 @@ function getGeoLocation() { location: location }; // addSellerToMap(oneSeller); - console.log("People Around: " + peopleAround); + console.log("From Shout Query - " + key + " is located at [" + location + "] which is within the query (" + distance.toFixed(2) + " km from center)"); + console.log("People Around: " + JSON.stringify(peopleAround)); }); - //update body $("body").append(pLocation); }); @@ -107,7 +110,7 @@ function getGeoLocation() { } // this is the call for YELP QUERY - WORKING - var yelpQuery = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=delis&latitude=39.951061&longitude=-75.165619&radius=8000"; + var yelpQuery = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=delis&latitude=39.951061&longitude=-75.165619&radius=5000"; //testing to get variables -- Needs WORK! // var yelpQuery = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=delis&latitude=" + userLocation[0] + "&longitude=" + userLocation[1] + "&radius=8000"; @@ -127,8 +130,6 @@ function getGeoLocation() { // ); } - - //google map function of generating user and icon function googleMapShout(userLat, userLng) { @@ -169,7 +170,7 @@ function googleMapShout(userLat, userLng) { ] - console.log(allUsers); + //loop through markers for (var i = 0; i < allUsers.length; i++) { addUserMarker(allUsers[i]); @@ -184,7 +185,7 @@ function googleMapShout(userLat, userLng) { map: map }); - console.log(user.coords.center); + // console.log(user.coords.center); //if user has an Icon if (user.iconImage) { @@ -217,7 +218,7 @@ function googleMapShout(userLat, userLng) { center: user.coords.center, radius: (user.coords.radius) * 1000 //kilometers }); - console.log(user.coords.radius); + // console.log(user.coords.radius); } } @@ -232,7 +233,7 @@ function setGeoFireUserInfo(snapshot) { var userRadius = snapshot[i].radius; geoFire.set(userName, userLocation).then(function () { - console.log("Current user " + userName + "'s location has been added to GeoFire and your location is " + userLocation); + // console.log("Current user " + userName + "'s location has been added to GeoFire and your location is " + userLocation); // geoFireRefPush.child(userName).onDisconnect().remove(); }); From 5a0f547ff3f6688f8f8636f6510b7e4f94503879 Mon Sep 17 00:00:00 2001 From: Jorge <3d.jorgesierra@gmail.com> Date: Sun, 24 Mar 2019 23:34:37 -0400 Subject: [PATCH 4/8] working location, need to test for other people --- assets/javascript/main.js | 102 ++++++++++++++++++++++++++++---------- index.html | 34 +++++++------ 2 files changed, 95 insertions(+), 41 deletions(-) diff --git a/assets/javascript/main.js b/assets/javascript/main.js index 0c2cad7..32e68a0 100644 --- a/assets/javascript/main.js +++ b/assets/javascript/main.js @@ -1,9 +1,9 @@ //Global variables var userLocation = []; var gMap; +var Radius = 5; - -// Initialize Firebase +// Initialize Firebase ---------------------------------------- var config = { apiKey: "AIzaSyBWlRO86vNl6sL5psQX5f7H9Lw_wsULP9g", authDomain: "geofiretest-9d07e.firebaseapp.com", @@ -16,7 +16,7 @@ firebase.initializeApp(config); //firebase database var firebaseData = firebase.database(); -var firebaseUserLocation = firebaseData.ref("firebase location"); +var firebaseUserLocation = firebaseData.ref("user location"); // geofire ref var geoFireRefPush = firebase.database().ref("/geofire-location").push(); // gefire initilize @@ -25,6 +25,7 @@ var geoFire = new GeoFire(geoFireRefPush); // geoquery var shoutQuery; +//------------------------------------------------------------------- // Just using HTML API for geo location and test it with other APIs function getGeoLocation() { @@ -51,7 +52,7 @@ function getGeoLocation() { lat: parseFloat(userLocation[0]), lng: parseFloat(userLocation[1]) }, - radius: 5 //kilometers + radius: Radius //kilometers }, user2 = { name: "user 2", @@ -59,11 +60,10 @@ function getGeoLocation() { lat: parseFloat(40.065494), lng: parseFloat(-75.091064) }, - radius: 5 //kilometers + radius: Radius //kilometers } ] - //update map with location of user and create an icon and circle. googleMapShout(userLocation[0], userLocation[1]); @@ -77,7 +77,7 @@ function getGeoLocation() { var shoutQuery = geoFire.query({ center: userLocation, - radius: 5 // kilometers + radius: Radius // kilometers }); // look at other people around @@ -87,16 +87,27 @@ function getGeoLocation() { lat: parseFloat(40.065494), lng: parseFloat(-75.091064) }, - radius: 5 //kilometers + radius: Radius //kilometers }; //check if someone is in your radius shoutQuery.on("key_entered", function (key, location, distance) { peopleAround = { id: key, - distance: distance, + distance: distance.toFixed(2) + "km", location: location }; + + //create a new location of the shouter who will then place it on the firebase query + if (Math.floor(distance) !== 0) { + addShouterMarker(userLocation); + console.log("Is distance 0 ? " + distance.toFixed); + } + + // locationOfShouter(userLocation); + + //show the shouter's location + // addSellerToMap(oneSeller); console.log("From Shout Query - " + key + " is located at [" + location + "] which is within the query (" + distance.toFixed(2) + " km from center)"); console.log("People Around: " + JSON.stringify(peopleAround)); @@ -133,17 +144,6 @@ function getGeoLocation() { //google map function of generating user and icon function googleMapShout(userLat, userLng) { - // initialize maps - - var map = new google.maps.Map(document.getElementById("map"), { - zoom: 11, - center: { - lat: userLat, - lng: userLng - } - }); - - var allUsers = [ firstUser = { @@ -152,7 +152,7 @@ function googleMapShout(userLat, userLng) { lat: userLat, lng: userLng }, - radius: 5 //kilometers + radius: Radius //kilometers }, iconImage: "./assets/images/map-icon.png", content: "

Hello Friends!

" @@ -169,7 +169,8 @@ function googleMapShout(userLat, userLng) { } ] - + //set map's center to shouter + map.panTo(allUsers[0].coords.center); //loop through markers for (var i = 0; i < allUsers.length; i++) { @@ -195,7 +196,6 @@ function googleMapShout(userLat, userLng) { // if it contains infoWindow text then create one if (user.content) { - //infoWindow is a pop up for the onClick var infoWindow = new google.maps.InfoWindow({ content: user.content @@ -218,10 +218,62 @@ function googleMapShout(userLat, userLng) { center: user.coords.center, radius: (user.coords.radius) * 1000 //kilometers }); - // console.log(user.coords.radius); } } +function addShouterMarker(shoutLocation) { + //Add marker + var shouter = { + coords: { + center: { + lat: shoutLocation[0], + lng: shoutLocation[1] + }, + radius: Radius //kilometers + }, + // iconImage: "./assets/images/map-icon.png", + content: "

This is a SHOUT!

" + }; + + var marker = new google.maps.Marker({ + position: shouter.coords.center, + map: map + }); + + // console.log(shouter.coords.center); + + //if user has an Icon + if (shouter.iconImage) { + //set Icon image + marker.setIcon(shouter.iconImage); + } + + // if it contains infoWindow text then create one + if (shouter.content) { + //infoWindow is a pop up for the onClick + var shouterInfoWindow = new google.maps.InfoWindow({ + content: shouter.content + }); + + } + + marker.addListener("click", () => { + + shouterInfoWindow.open(map, marker); + }); + + var cityCircle = new google.maps.Circle({ + strokeColor: '#00bcd4', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#f33839', + fillOpacity: 0.35, + map: map, + center: shouter.coords.center, + radius: (shouter.coords.radius) * 1000 //kilometers + }); +} + function setGeoFireUserInfo(snapshot) { //get snapshot vallue var snapshot = snapshot.val(); @@ -230,7 +282,7 @@ function setGeoFireUserInfo(snapshot) { for (var i = 0; i < snapshot.length; i++) { var userName = snapshot[i].name; var userLocation = [snapshot[i].center.lat, snapshot[i].center.lng]; - var userRadius = snapshot[i].radius; + var Radius = snapshot[i].radius; geoFire.set(userName, userLocation).then(function () { // console.log("Current user " + userName + "'s location has been added to GeoFire and your location is " + userLocation); diff --git a/index.html b/index.html index 932c14a..c8fe7a8 100644 --- a/index.html +++ b/index.html @@ -5,19 +5,19 @@ - + Shout! - - - - - - - - - + + + + + + + + + @@ -35,8 +35,11 @@

Google Map

- + - + From 7dd51dabf826026ccc2eacff1fd32a4ac75f9550 Mon Sep 17 00:00:00 2001 From: Jorge <3d.jorgesierra@gmail.com> Date: Mon, 25 Mar 2019 01:05:04 -0400 Subject: [PATCH 5/8] Need to check agaisnt different users --- assets/javascript/Geofire.1.js | 47 ------- assets/javascript/geohash.js | 244 +++++++++++++++++++++++++++++++++ assets/javascript/main.js | 70 ++++++++-- 3 files changed, 299 insertions(+), 62 deletions(-) delete mode 100644 assets/javascript/Geofire.1.js create mode 100644 assets/javascript/geohash.js diff --git a/assets/javascript/Geofire.1.js b/assets/javascript/Geofire.1.js deleted file mode 100644 index 2e39d9e..0000000 --- a/assets/javascript/Geofire.1.js +++ /dev/null @@ -1,47 +0,0 @@ - // Initialize Firebase - var config = { - apiKey: "AIzaSyBWlRO86vNl6sL5psQX5f7H9Lw_wsULP9g", - authDomain: "geofiretest-9d07e.firebaseapp.com", - databaseURL: "https://geofiretest-9d07e.firebaseio.com", - projectId: "geofiretest-9d07e", - storageBucket: "geofiretest-9d07e.appspot.com", - messagingSenderId: "680094207901" - }; - firebase.initializeApp(config); - - //variables for firebase database - var firebaseData = firebase.database(); -// geofire ref -var firebaseRef = firebase.database().ref().push(); - var geoFire = new GeoFire(firebaseRef); - - //setting initial location - geoFire.set("user_key", [37.785326, -122.405696]).then(function (){ - console.log("provided key has been added to Geofire"); - }, function (error){ - console.log("error: " + error); - }); - - //getting initial location - geoFire.get("user_key").then(function(location) { - if (location === null) { - console.log("Provided key is not in GeoFire"); - } - else { - console.log("Provided key has a location of " + location); - } - }, function(error) { - console.log("Error: " + error); - }); - - //setup a query that looks at the user's location. - var geoQuery = geoFire.geoQuery({ - center: [37.4, -122.6], - radius: 1.609 //kilometers - }); - - //check to see if anything has entered this location - geoQuery.on("key_entered", function(key, location, distance) { - console.log("Bicycle shop " + key + " found at " + location + " (" + distance + " km away)"); - }); - diff --git a/assets/javascript/geohash.js b/assets/javascript/geohash.js new file mode 100644 index 0000000..fc92468 --- /dev/null +++ b/assets/javascript/geohash.js @@ -0,0 +1,244 @@ +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +/* Geohash encoding/decoding and associated functions (c) Chris Veness 2014-2016 / MIT Licence */ +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + +'use strict'; + + +/** + * Geohash encode, decode, bounds, neighbours. + * + * @namespace + */ +var Geohash = {}; + +/* (Geohash-specific) Base32 map */ +Geohash.base32 = '0123456789bcdefghjkmnpqrstuvwxyz'; + +/** + * Encodes latitude/longitude to geohash, either to specified precision or to automatically + * evaluated precision. + * + * @param {number} lat - Latitude in degrees. + * @param {number} lon - Longitude in degrees. + * @param {number} [precision] - Number of characters in resulting geohash. + * @returns {string} Geohash of supplied latitude/longitude. + * @throws Invalid geohash. + * + * @example + * var geohash = Geohash.encode(52.205, 0.119, 7); // geohash: 'u120fxw' + */ +Geohash.encode = function(lat, lon, precision) { + // infer precision? + if (typeof precision == 'undefined') { + // refine geohash until it matches precision of supplied lat/lon + for (var p=1; p<=12; p++) { + var hash = Geohash.encode(lat, lon, p); + var posn = Geohash.decode(hash); + if (posn.lat==lat && posn.lon==lon) return hash; + } + precision = 12; // set to maximum + } + + lat = Number(lat); + lon = Number(lon); + precision = Number(precision); + + if (isNaN(lat) || isNaN(lon) || isNaN(precision)) throw new Error('Invalid geohash'); + + var idx = 0; // index into base32 map + var bit = 0; // each char holds 5 bits + var evenBit = true; + var geohash = ''; + + var latMin = -90, latMax = 90; + var lonMin = -180, lonMax = 180; + + while (geohash.length < precision) { + if (evenBit) { + // bisect E-W longitude + var lonMid = (lonMin + lonMax) / 2; + if (lon >= lonMid) { + idx = idx*2 + 1; + lonMin = lonMid; + } else { + idx = idx*2; + lonMax = lonMid; + } + } else { + // bisect N-S latitude + var latMid = (latMin + latMax) / 2; + if (lat >= latMid) { + idx = idx*2 + 1; + latMin = latMid; + } else { + idx = idx*2; + latMax = latMid; + } + } + evenBit = !evenBit; + + if (++bit == 5) { + // 5 bits gives us a character: append it and start over + geohash += Geohash.base32.charAt(idx); + bit = 0; + idx = 0; + } + } + + return geohash; +}; + + +/** + * Decode geohash to latitude/longitude (location is approximate centre of geohash cell, + * to reasonable precision). + * + * @param {string} geohash - Geohash string to be converted to latitude/longitude. + * @returns {{lat:number, lon:number}} (Center of) geohashed location. + * @throws Invalid geohash. + * + * @example + * var latlon = Geohash.decode('u120fxw'); // latlon: { lat: 52.205, lon: 0.1188 } + */ +Geohash.decode = function(geohash) { + + var bounds = Geohash.bounds(geohash); // <-- the hard work + // now just determine the centre of the cell... + + var latMin = bounds.sw.lat, lonMin = bounds.sw.lon; + var latMax = bounds.ne.lat, lonMax = bounds.ne.lon; + + // cell centre + var lat = (latMin + latMax)/2; + var lon = (lonMin + lonMax)/2; + + // round to close to centre without excessive precision: ⌊2-log10(Δ°)⌋ decimal places + lat = lat.toFixed(Math.floor(2-Math.log(latMax-latMin)/Math.LN10)); + lon = lon.toFixed(Math.floor(2-Math.log(lonMax-lonMin)/Math.LN10)); + + return { lat: Number(lat), lon: Number(lon) }; +}; + + +/** + * Returns SW/NE latitude/longitude bounds of specified geohash. + * + * @param {string} geohash - Cell that bounds are required of. + * @returns {{sw: {lat: number, lon: number}, ne: {lat: number, lon: number}}} + * @throws Invalid geohash. + */ +Geohash.bounds = function(geohash) { + if (geohash.length === 0) throw new Error('Invalid geohash'); + + geohash = geohash.toLowerCase(); + + var evenBit = true; + var latMin = -90, latMax = 90; + var lonMin = -180, lonMax = 180; + + for (var i=0; i=0; n--) { + var bitN = idx >> n & 1; + if (evenBit) { + // longitude + var lonMid = (lonMin+lonMax) / 2; + if (bitN == 1) { + lonMin = lonMid; + } else { + lonMax = lonMid; + } + } else { + // latitude + var latMid = (latMin+latMax) / 2; + if (bitN == 1) { + latMin = latMid; + } else { + latMax = latMid; + } + } + evenBit = !evenBit; + } + } + + var bounds = { + sw: { lat: latMin, lon: lonMin }, + ne: { lat: latMax, lon: lonMax }, + }; + + return bounds; +}; + + +/** + * Determines adjacent cell in given direction. + * + * @param geohash - Cell to which adjacent cell is required. + * @param direction - Direction from geohash (N/S/E/W). + * @returns {string} Geocode of adjacent cell. + * @throws Invalid geohash. + */ +Geohash.adjacent = function(geohash, direction) { + // based on github.com/davetroy/geohash-js + + geohash = geohash.toLowerCase(); + direction = direction.toLowerCase(); + + if (geohash.length === 0) throw new Error('Invalid geohash'); + if ('nsew'.indexOf(direction) == -1) throw new Error('Invalid direction'); + + var neighbour = { + n: [ 'p0r21436x8zb9dcf5h7kjnmqesgutwvy', 'bc01fg45238967deuvhjyznpkmstqrwx' ], + s: [ '14365h7k9dcfesgujnmqp0r2twvyx8zb', '238967debc01fg45kmstqrwxuvhjyznp' ], + e: [ 'bc01fg45238967deuvhjyznpkmstqrwx', 'p0r21436x8zb9dcf5h7kjnmqesgutwvy' ], + w: [ '238967debc01fg45kmstqrwxuvhjyznp', '14365h7k9dcfesgujnmqp0r2twvyx8zb' ], + }; + var border = { + n: [ 'prxz', 'bcfguvyz' ], + s: [ '028b', '0145hjnp' ], + e: [ 'bcfguvyz', 'prxz' ], + w: [ '0145hjnp', '028b' ], + }; + + var lastCh = geohash.slice(-1); // last character of hash + var parent = geohash.slice(0, -1); // hash without last character + + var type = geohash.length % 2; + + // check for edge-cases which don't share common prefix + if (border[direction][type].indexOf(lastCh) != -1 && parent !== '') { + parent = Geohash.adjacent(parent, direction); + } + + // append letter for direction to parent + return parent + Geohash.base32.charAt(neighbour[direction][type].indexOf(lastCh)); +}; + + +/** + * Returns all 8 adjacent cells to specified geohash. + * + * @param {string} geohash - Geohash neighbours are required of. + * @returns {{n,ne,e,se,s,sw,w,nw: string}} + * @throws Invalid geohash. + */ +Geohash.neighbours = function(geohash) { + return { + 'n': Geohash.adjacent(geohash, 'n'), + 'ne': Geohash.adjacent(Geohash.adjacent(geohash, 'n'), 'e'), + 'e': Geohash.adjacent(geohash, 'e'), + 'se': Geohash.adjacent(Geohash.adjacent(geohash, 's'), 'e'), + 's': Geohash.adjacent(geohash, 's'), + 'sw': Geohash.adjacent(Geohash.adjacent(geohash, 's'), 'w'), + 'w': Geohash.adjacent(geohash, 'w'), + 'nw': Geohash.adjacent(Geohash.adjacent(geohash, 'n'), 'w'), + }; +}; + + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +if (typeof module != 'undefined' && module.exports) module.exports = Geohash; // CommonJS, node.js \ No newline at end of file diff --git a/assets/javascript/main.js b/assets/javascript/main.js index 32e68a0..b56f59a 100644 --- a/assets/javascript/main.js +++ b/assets/javascript/main.js @@ -16,16 +16,27 @@ firebase.initializeApp(config); //firebase database var firebaseData = firebase.database(); +//firebase userlocation var firebaseUserLocation = firebaseData.ref("user location"); -// geofire ref +//get user list +var userListRef = firebaseData.ref("online presence"); +//current User Ref +var currentUserRef = userListRef.push(); +//Add ourself to the list when online +var ourPresenceRef = firebaseData.ref(".info/connected"); + + +//GEOFIRE---------------- +//geofire ref var geoFireRefPush = firebase.database().ref("/geofire-location").push(); -// gefire initilize +//gefire initilize var geoFire = new GeoFire(geoFireRefPush); //-------- // geoquery var shoutQuery; //------------------------------------------------------------------- + // Just using HTML API for geo location and test it with other APIs function getGeoLocation() { @@ -53,15 +64,15 @@ function getGeoLocation() { lng: parseFloat(userLocation[1]) }, radius: Radius //kilometers - }, - user2 = { - name: "user 2", - center: { - lat: parseFloat(40.065494), - lng: parseFloat(-75.091064) - }, - radius: Radius //kilometers } + // user2 = { + // name: "user 2", + // center: { + // lat: parseFloat(40.065494), + // lng: parseFloat(-75.091064) + // }, + // radius: Radius //kilometers + // } ] //update map with location of user and create an icon and circle. @@ -97,20 +108,20 @@ function getGeoLocation() { distance: distance.toFixed(2) + "km", location: location }; - + //create a new location of the shouter who will then place it on the firebase query if (Math.floor(distance) !== 0) { addShouterMarker(userLocation); - console.log("Is distance 0 ? " + distance.toFixed); + console.log("People Around: " + JSON.stringify(peopleAround)); } - + // locationOfShouter(userLocation); //show the shouter's location // addSellerToMap(oneSeller); console.log("From Shout Query - " + key + " is located at [" + location + "] which is within the query (" + distance.toFixed(2) + " km from center)"); - console.log("People Around: " + JSON.stringify(peopleAround)); + }); //update body @@ -296,5 +307,34 @@ function errorObject(errorObject) { console.log("The read failed: " + errorObject.code); }; -// Execute functions +function usersOnline() { + ourPresenceRef.on("value", function (snapshot) { + if (snapshot.val()) { + // remove ourselves when we disconnect + currentUserRef.onDisconnect().remove(); + + currentUserRef.set(true); + } + }); + + //number of online users is the number of objects in the presence list. + userListRef.on("value", function (snapshot) { + // remove ourselves when we disconnect + currentUserRef.onDisconnect().remove(); + //user is present + currentUserRef.set(true); + console.log("# of online users = " + snapshot.numChildren()); + }); + + //get user location + + +} + + +// Execute Initial functions---------------- +// Check who's online +usersOnline(); + +//on click shout $(document).on("click", "#getGeoLocation", getGeoLocation); \ No newline at end of file From 6242f4c74f29dfde77cd0886fde720c6b718a116 Mon Sep 17 00:00:00 2001 From: Jorge <3d.jorgesierra@gmail.com> Date: Mon, 25 Mar 2019 01:26:39 -0400 Subject: [PATCH 6/8] set up work around to get individual user location --- assets/javascript/main.js | 4 ++++ index.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/javascript/main.js b/assets/javascript/main.js index b56f59a..bd16aae 100644 --- a/assets/javascript/main.js +++ b/assets/javascript/main.js @@ -50,6 +50,10 @@ function getGeoLocation() { userLocation.push(position.coords.latitude); userLocation.push(position.coords.longitude); + //add to data-location attribute for This call. + $(this).attr("data-lat", position.coords.latitude.toString()); + $(this).attr("data-lng", position.coords.longitude.toString()); + //display lattitude and longitude in dom var pLocation = $("

"); pLocation.text("The Lattitude-array: " + userLocation[0] + " and the longitude-array: " + userLocation[1]); diff --git a/index.html b/index.html index c8fe7a8..4fd2660 100644 --- a/index.html +++ b/index.html @@ -28,7 +28,7 @@

Google Map

- +
From a6b596164f700903ac191bdadcc04e9a72e9128d Mon Sep 17 00:00:00 2001 From: Jorge <3d.jorgesierra@gmail.com> Date: Mon, 25 Mar 2019 09:40:09 -0400 Subject: [PATCH 7/8] added drop down icon --- assets/javascript/geoTest.js | 50 -------------------------------- assets/javascript/main.js | 55 ++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 74 deletions(-) delete mode 100644 assets/javascript/geoTest.js diff --git a/assets/javascript/geoTest.js b/assets/javascript/geoTest.js deleted file mode 100644 index 9a33f6a..0000000 --- a/assets/javascript/geoTest.js +++ /dev/null @@ -1,50 +0,0 @@ - // Initialize Firebase - var config = { - apiKey: "AIzaSyBWlRO86vNl6sL5psQX5f7H9Lw_wsULP9g", - authDomain: "geofiretest-9d07e.firebaseapp.com", - databaseURL: "https://geofiretest-9d07e.firebaseio.com", - projectId: "geofiretest-9d07e", - storageBucket: "geofiretest-9d07e.appspot.com", - messagingSenderId: "680094207901" -}; -firebase.initializeApp(config); - -//variables for firebase database -var firebaseData = firebase.database(); -// geofire ref -var firebaseRefPush = firebase.database().ref().push(); - -var geoFire = new GeoFire(firebaseRefPush); -console.log("firebase "+ geoFire); - -//setting initial location -geoFire.set("user_key", [37.785326, -122.405696]).then(function (){ - console.log("provided key has been added to Geofire"); -}, function (error){ - console.log("error: " + error); -}); - - -//getting initial location -geoFire.get("user_key").then(function(location) { - if (location === null) { - console.log("Provided key is not in GeoFire"); - } - else { - console.log("Provided key has a location of " + location); - } -}, function(error) { - console.log("Error: " + error); -}); - -//setup a query that looks at the user's location. -var geoQuery = geoFire.query({ - center: [37.4, -122.6], - radius: 1.609 //kilometers -}); - -//check to see if anything has entered this location -geoQuery.on("key_entered", function(key, location, distance) { - console.log("Bicycle shop " + key + " found at " + location + " (" + distance + " km away)"); -}); - diff --git a/assets/javascript/main.js b/assets/javascript/main.js index bd16aae..25fbd0f 100644 --- a/assets/javascript/main.js +++ b/assets/javascript/main.js @@ -25,8 +25,7 @@ var currentUserRef = userListRef.push(); //Add ourself to the list when online var ourPresenceRef = firebaseData.ref(".info/connected"); - -//GEOFIRE---------------- +//GEOFIRE------------------------------------------------------- //geofire ref var geoFireRefPush = firebase.database().ref("/geofire-location").push(); //gefire initilize @@ -36,6 +35,9 @@ var geoFire = new GeoFire(geoFireRefPush); var shoutQuery; //------------------------------------------------------------------- +//TODO: When you land on page ask the user for the location and store on to the users firebase ID +//TODO: When you press the shout button, get that specific users location and update firebase with that location +//TODO: Use that Shout Location and update the browser to land a marker on the New Location // Just using HTML API for geo location and test it with other APIs function getGeoLocation() { @@ -50,7 +52,7 @@ function getGeoLocation() { userLocation.push(position.coords.latitude); userLocation.push(position.coords.longitude); - //add to data-location attribute for This call. + //have user unique ID be stored and referenced when pressing the button. $(this).attr("data-lat", position.coords.latitude.toString()); $(this).attr("data-lng", position.coords.longitude.toString()); @@ -58,7 +60,6 @@ function getGeoLocation() { var pLocation = $("

"); pLocation.text("The Lattitude-array: " + userLocation[0] + " and the longitude-array: " + userLocation[1]); - //Set user's info for fireBasae var userInfo = [ user1 = { @@ -89,7 +90,6 @@ function getGeoLocation() { firebaseUserLocation.set(userInfo); //user who pressed the shout set geoQuery - var shoutQuery = geoFire.query({ center: userLocation, radius: Radius // kilometers @@ -112,7 +112,7 @@ function getGeoLocation() { distance: distance.toFixed(2) + "km", location: location }; - + //create a new location of the shouter who will then place it on the firebase query if (Math.floor(distance) !== 0) { addShouterMarker(userLocation); @@ -125,7 +125,7 @@ function getGeoLocation() { // addSellerToMap(oneSeller); console.log("From Shout Query - " + key + " is located at [" + location + "] which is within the query (" + distance.toFixed(2) + " km from center)"); - + }); //update body @@ -184,23 +184,28 @@ function googleMapShout(userLat, userLng) { } ] + //set map's center to shouter map.panTo(allUsers[0].coords.center); - //loop through markers + //loop through markers and drop for (var i = 0; i < allUsers.length; i++) { - addUserMarker(allUsers[i]); - } + var userIndex = allUsers[i]; + // window.setTimeout( function(){ + // addUserMarker(userIndex) + // },200) ; + addUserMarker(userIndex); + } //function Marker function addUserMarker(user) { - //Add marker + var marker = new google.maps.Marker({ position: user.coords.center, - map: map + map: map, + animation: google.maps.Animation.DROP, }); - // console.log(user.coords.center); //if user has an Icon @@ -215,24 +220,25 @@ function googleMapShout(userLat, userLng) { var infoWindow = new google.maps.InfoWindow({ content: user.content }); - } - marker.addListener("click", () => { - - infoWindow.open(map, marker); - }); - + // create circle var cityCircle = new google.maps.Circle({ strokeColor: '#FF0000', - strokeOpacity: 0.8, + strokeOpacity: 0.15, strokeWeight: 2, fillColor: '#FF0000', - fillOpacity: 0.35, + fillOpacity: 0.15, map: map, center: user.coords.center, radius: (user.coords.radius) * 1000 //kilometers }); + + //check if marker has been clicked + marker.addListener("click", () => { + + infoWindow.open(map, marker); + }); } } @@ -252,7 +258,8 @@ function addShouterMarker(shoutLocation) { var marker = new google.maps.Marker({ position: shouter.coords.center, - map: map + map: map, + animation: google.maps.Animation.DROP }); // console.log(shouter.coords.center); @@ -279,7 +286,7 @@ function addShouterMarker(shoutLocation) { var cityCircle = new google.maps.Circle({ strokeColor: '#00bcd4', - strokeOpacity: 0.8, + strokeOpacity: 0.3, strokeWeight: 2, fillColor: '#f33839', fillOpacity: 0.35, @@ -332,7 +339,7 @@ function usersOnline() { //get user location - + } From 2ed9fcc79e2bc98dab6a69c2505240a51256c714 Mon Sep 17 00:00:00 2001 From: Jorge Sierra <3d.jorgesierra@gmail.com> Date: Mon, 25 Mar 2019 19:27:45 -0400 Subject: [PATCH 8/8] fix --- assets/javascript/main.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/assets/javascript/main.js b/assets/javascript/main.js index 25fbd0f..5fa3b96 100644 --- a/assets/javascript/main.js +++ b/assets/javascript/main.js @@ -142,18 +142,32 @@ function getGeoLocation() { // var yelpQuery = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=delis&latitude=" + userLocation[0] + "&longitude=" + userLocation[1] + "&radius=8000"; var yelpAPI = "1QpSc4B1zI5GuI56PDAAvAfpfcsLg9LWuHRfVCeG4TIDDxRe3hGT-sxlU5h5DD0AdLgu-HHoa2cM4m1WaAefYoboIPdVHv0mCjivrwQrdU11FCFl2hd8-iaaTKOTXHYx"; - // //-----------YELP CALL - // $.ajax({ - // url: yelpQuery, - // headers: { - // 'Authorization': "Bearer " + yelpAPI, - // }, - // method: "GET" - // }).then((yelpResponse) => { - // console.log("Yelp response: "+ yelpResponse); - // } - - // ); + //-----------YELP CALL + $.ajax({ + url: yelpQuery, + headers: { + 'Authorization': "Bearer " + yelpAPI, + }, + method: "GET" + }).then((yelpResponse) => { + console.log(yelpResponse); + + var result = $("

"); + for (var i = 0; i < 5; i++) { + var name = yelpResponse.businesses[i].name; + var ratings = yelpResponse.businesses[i].rating; + var is_closed = yelpResponse.businesses[i].is_closed; + var location = yelpResponse.businesses[i].location.address1; + var yelpLat = yelpResponse.businesses[i].coordinates.latitude; + var yelpLong = yelpResponse.businesses[i].coordinates.longitude; + $("#name").append($("

").text(name)); + $("#ratings").append($("

").text(ratings)); + $("#is_closed").append($("

").text(is_closed)); + $("#location").append($("

").text(location)); + + } + + }); } //google map function of generating user and icon