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
|
define.class(function(exports){
var FourSquareLib = exports
this.atConstructor = function(clientid, secret) {
var config = {
foursquare: {},
secrets: {
clientId: process.env.FOURSQUARE_CLIENT_ID || clientid,
clientSecret: process.env.FOURSQUARE_SECRET || secret,
redirectUrl: 'redirect'
}
}
this.foursquare = require('node-foursquare')(config)
this.accessToken = ''
}
this.search = function(options, callback) {
options = options || {}
if (options['location'] === undefined) options['location'] = [37.859603, -122.491075]
if (options['openNow'] === undefined) options['openNow'] = 0
if (options['venuePhotos'] === undefined) options['venuePhotos'] = 1
if (options['limit'] === undefined) options['limit'] = 250
if (options['radius'] === undefined) options['radius'] = 1000
if (options['section'] === undefined) options['section'] = 'coffee'
this.foursquare.Venues.explore(options.location[0], options.location[1], null, options, this.accessToken, function(error, data) {
if (error) console.error('error', error)
venues = []
if (data && data.groups) {
var items = data.groups[0].items
for (var i in items) {
var venue = items[i].venue
var photoUrl
if (venue.photos && venue.photos.groups) {
try {
var group = venue.photos.groups[0]
if (!group) continue
var item = venue.photos.groups[0].items[0]
photoUrl = item.prefix + '300x300' + item.suffix
}
catch (ex) {
console.error('Exception', ex)
}
}
venues.push({
url: photoUrl,
id: venue.id,
title: venue.name,
width: 300,
height: 300,
latitude: venue.location.lat,
longitude: venue.location.lng,
category: venue.categories[0].shortName,
rating: venue.rating,
price: venue.price ? venue.price.tier : 0
})
}
}
callback(venues)
})
}
})
|