Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
436 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict' | ||
|
||
var http = require("http"), | ||
async = require('async'), | ||
search = require("./foursquare_search"), | ||
getFoodPics = require("./foursquare_foodpics"); | ||
|
||
/** Main Search **/ | ||
|
||
|
||
function parseResults (req, parsedData) { | ||
|
||
//items is an array of venues | ||
var items = parsedData.response.groups[0].items; | ||
var result = []; | ||
var venueIds = []; | ||
|
||
for (i = 0; i < items.length; i++) { | ||
var venue = items[i].venue | ||
var id = venue.id; | ||
var name = venue.name; | ||
|
||
// Foursquare already provides a formatted address and phone number for us | ||
var location = venue.location; | ||
var address = venue.location && venue.location.formattedAddress; | ||
var contact = venue.contact && venue.contact.formattedPhone; | ||
var stats = venue.stats; | ||
var checkins = venue.hereNow; | ||
// This will return null if venue.price is undefined | ||
var price = venue.price && venue.price.tier; | ||
var rating = venue.rating; | ||
// Foursquare also gives us it's best guess if a venue is open | ||
var hours = venue.hours && venue.hours.isOpen; | ||
var url = venue.url; | ||
|
||
result.push({ | ||
id: id, | ||
name: name, | ||
location: location, | ||
address: address, | ||
contact: contact, | ||
stats: stats, | ||
checkins: checkins, | ||
price: price, | ||
rating: rating, | ||
open: hours, | ||
url: url | ||
}); | ||
|
||
venueIds.push(id); | ||
} | ||
return [result, venueIds]; | ||
}; | ||
|
||
|
||
exports.searchFood = function(req, res) { | ||
var searchQuery = { | ||
query: req.query.query, | ||
lat: req.query.lat, | ||
lng: req.query.lng | ||
}; | ||
|
||
search(searchQuery, function(err, parsedData){ | ||
if (err) { | ||
return console.error('There was an error: ' + err.message); | ||
} | ||
var results = parseResults(req, parsedData); | ||
var result_list = results[0]; | ||
var venueIds = results[1]; | ||
|
||
// makes call to getAllFood | ||
getFoodPics(venueIds, function(err, photoData){ | ||
console.log("getFoodPics called with photoData\n", photoData); | ||
|
||
var allVenues = { | ||
result_list: result_list, | ||
photoObjs: photoData | ||
} | ||
|
||
res.json(allVenues); | ||
}); | ||
|
||
}); | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//config.js | ||
|
||
module.exports.foursquare = { | ||
// Foursquare API keys in development | ||
'clientId' : 'PJERQVMJ3DURUE5YKR50CSQGMYIPIBZQESKBK35SC1ZXQJ0R', | ||
'clientSecret' : 'XKGURJJDVQT3TSARQJDUR1BGZ1YIKR2K5Z4GGQOJ5RCAXTM3' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict' | ||
|
||
var async = require('async'); | ||
var http = require('http'); | ||
var https = require('https'); | ||
var secrets = require('./foursquare_config'); | ||
var foursquareClientId = process.env.FS_CLIENT_ID || secrets.foursquare.clientId; | ||
var foursquareClientSecret = process.env.FS_CLIENT_SECRET || secrets.foursquare.clientSecret; | ||
var photoObjs = []; | ||
|
||
// get food pics for one venue | ||
var getOneFood = function(vId, cb){ | ||
var options = { | ||
host: 'api.foursquare.com', | ||
port: 443, | ||
path: '/v2/venues/' + vId + "/photos?limit=2&v=20150125&client_id=" + foursquareClientId + '&client_secret=' + foursquareClientSecret, | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
|
||
var req = https.get(options, function(res) { | ||
var dataChunks = []; | ||
res.on('data', function(chunk) { | ||
dataChunks.push(chunk); | ||
}).on('end', function() { | ||
var body = Buffer.concat(dataChunks); | ||
var stringBody = body.toString('utf-8'); | ||
var parsedData = JSON.parse(stringBody); | ||
var photoData = parsedData['response']['photos']['items']; | ||
for (var i = 0; i < photoData.length ; i++) { | ||
var obj = { | ||
url: photoData[i]['prefix']+"300x300"+photoData[i]['suffix'], | ||
venueId: vId | ||
} | ||
if (obj !== undefined) { | ||
photoObjs.push(obj); | ||
} | ||
} | ||
console.log("getOneFood for vId: ", vId); | ||
cb(null); | ||
}); | ||
}); | ||
|
||
req.on('error', function(error) { | ||
cb(error); | ||
}); | ||
|
||
req.end(); | ||
} | ||
|
||
var getAllFood = function(venueIds, callback) { | ||
async.each(venueIds, getOneFood, function(err) { | ||
if( err ) { | ||
console.log('getAllFood error', err); | ||
} else { | ||
console.log("finished async.each\n", photoObjs); | ||
callback(null, photoObjs); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = getAllFood; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict' | ||
|
||
module.exports = function(query, callback) { | ||
var http = require('http'); | ||
var https = require('https'); | ||
var secrets = require('./foursquare_config'); | ||
// We'll get our API keys from a config file if we can't find an 'FS_CLIENT_ID' environmental variable | ||
var foursquareClientId = process.env.FS_CLIENT_ID || secrets.foursquare.clientId; | ||
var foursquareClientSecret = process.env.FS_CLIENT_SECRET || secrets.foursquare.clientSecret; | ||
|
||
var lat = query.lat, | ||
lng = query.lng; | ||
|
||
var options = { | ||
host: 'api.foursquare.com', | ||
port: 443, | ||
// path: '/v2/venues/explore?client_id=' + foursquareClientId + '&client_secret=' + foursquareClientSecret + '&v=20140125&ll=40.72078,-74.001119&query=' + query, | ||
|
||
path: '/v2/venues/explore?client_id=' + foursquareClientId + '&client_secret=' + foursquareClientSecret + '&v=20150125&ll=' + lat + "," + lng + '&query=' + query.query, | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
|
||
var req = https.request(options, function(res) { | ||
var dataChunks = []; | ||
res.on('data', function(chunk) { | ||
dataChunks.push(chunk); | ||
}).on('end', function() { | ||
var body = Buffer.concat(dataChunks); | ||
var stringBody = body.toString('utf-8'); | ||
var parsedData = JSON.parse(stringBody); | ||
// API call | ||
console.log(options.host + options.path); | ||
|
||
callback(null, parsedData); | ||
}); | ||
}); | ||
|
||
req.end(); | ||
|
||
req.on('error', function(error) { | ||
console.log('ERROR: ' + error.message); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
module.exports = function(app) { | ||
var foursquare = require('../../app/controllers/foursquare.server.controller'); | ||
|
||
// foursquare search Routes | ||
app.route('/searchFood').get(foursquare.searchFood); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,91 @@ | ||
'use strict'; | ||
|
||
var setUpMap = function(){ | ||
var getLocation = function() { | ||
if (navigator.geolocation) { | ||
navigator.geolocation.getCurrentPosition(showPosition); | ||
} else { | ||
console.log("Geolocation is not supported by this browser."); | ||
} | ||
} | ||
|
||
var showPosition = function(position) { | ||
var theLatLng = new google.maps.LatLng(Number(position.coords.latitude), Number(position.coords.longitude)); | ||
console.log("showposition", theLatLng); | ||
|
||
document.getElementById('lat').setAttribute("value", position.coords.latitude); | ||
document.getElementById('lng').setAttribute("value", position.coords.longitude); | ||
|
||
var mapOptions = { | ||
zoom: 15, | ||
center: theLatLng | ||
}; | ||
|
||
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); | ||
|
||
var centerMarker = new google.maps.Marker({ | ||
position: theLatLng, | ||
map: map, | ||
title: "Center", | ||
icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png' | ||
}); | ||
|
||
var infoWindows = []; | ||
var markers = []; | ||
var latLngBounds = new google.maps.LatLngBounds(); | ||
|
||
if (latLng) { | ||
latLng.forEach(function(item){ | ||
infoWindows.push(new google.maps.InfoWindow({ | ||
content: "<div>" + item[2] + "</div>" + "<div>" + "Rating: " + item[3] + "</div>" + | ||
"<div>" + "Price Level: " + item[4] + "</div>" | ||
})); | ||
|
||
var latLng = new google.maps.LatLng(item[0], item[1]); | ||
|
||
markers.push(new google.maps.Marker({ | ||
position: latLng, | ||
map: map, | ||
title: item[2], | ||
icon: 'http://maps.google.com/mapfiles/ms/icons/red-dot.png' | ||
})); | ||
latLngBounds.extend(latLng); | ||
}); | ||
} | ||
|
||
map.setCenter(latLngBounds.getCenter()); | ||
map.fitBounds(latLngBounds); | ||
|
||
//console.log(infoWindows) | ||
for (var i = 0; i < markers.length; i++) { | ||
google.maps.event.addListener(markers[i], 'click', function(innerKey) { | ||
var clicks = 0; | ||
return function() { | ||
// console.log(infoWindows[i]); | ||
clicks++; | ||
infoWindows[innerKey].open(map, markers[innerKey]); | ||
} | ||
}(i)); | ||
} | ||
} | ||
|
||
getLocation(); | ||
} | ||
|
||
|
||
angular.module('core').controller('HomeController', ['$scope', 'Authentication', | ||
function($scope, Authentication) { | ||
// This provides Authentication context. | ||
$scope.authentication = Authentication; | ||
} | ||
|
||
var loadScript = function() { | ||
var script = document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&' + 'callback=setUpMap'; | ||
document.body.appendChild(script); | ||
} | ||
|
||
loadScript(); | ||
} | ||
|
||
]); |
Oops, something went wrong.