· 9 years ago · Nov 27, 2016, 10:56 PM
1function populateInfoWindow(marker, infowindow) {
2//Check to make sure the infowindow is not already opened on this marker.
3if (infowindow.marker != marker) {
4 infowindow.marker = marker;
5
6 infowindow.setContent('<div>' + marker.title + '</div> <br>' +
7 '<img src="images/yelp-2c.png" alt="Yelp Logo" style="width:100px;height:50px;">' +
8 '<div>' + callYelpAPI(marker.id) + '</div> <img src="images/19x19_5.png" alt=".5">');
9 //marker.stars[marker.id]()
10 //callYelpAPI(marker.id)
11 console.log(callYelpAPI(marker.id));
12 infowindow.open(map, marker);
13 //Make sure the marker property is cleared if the infowindow is closed.
14 infowindow.addListener('closeclick', function() {
15 infowindow.setMarker(null);
16 });
17}
18
19function nonce_generate() {
20 return (Math.floor(Math.random() * 1e12).toString());
21}
22
23
24
25
26var parameters = {
27 oauth_consumer_key: 'h7e9cHmibtiOAeUH_GJ1QA', //consumer key
28 oauth_token: 'CQpP53MNeigAwK1wYmhwaguuc5I3GvEB', // Token
29 oauth_nonce: nonce_generate(),
30 oauth_timestamp: Math.floor(Date.now() / 1000),
31 oauth_signature_method: 'HMAC-SHA1',
32 oauth_version: '1.0',
33 callback: 'cb',
34 //term: 'Tacos El Norte',
35 //location: 'Highwood,Il'
36 // id: 'tacos-el-norte-highwood'
37 id: Model.locations[i].yelpId
38
39
40};
41//Consumer Secret //Token Secret
42var yelp_url = 'https://api.yelp.com/v2/' + 'business/' + parameters.id;
43
44//var yelp_url = 'https://api.yelp.com/v2/' + 'search/';
45
46var encodedSignature = oauthSignature.generate('GET', yelp_url, parameters, '3fH3EJysPQ0Am-C2miz4G_tzirE', '6Vqup-75LvlpqctaNZYerug_rbw', Model.vm.stars[i]);
47parameters.oauth_signature = encodedSignature;
48
49var settings = {
50 url: yelp_url,
51 data: parameters,
52 cache: true, // This is crucial to include as well to prevent jQuery from adding on a cache-buster parameter "_=23489489749837", invalidating our oauth-signature
53 dataType: 'jsonp',
54 success: function(results) {
55 var n = results.display_phone.toString();
56 console.log(n);
57 return n;
58
59 //Model.vm.stars.push(yelpRating);
60 //console.log(Model.vm.stars());
61 //console.log(Model.vm.stars[i]);
62 //console.log(yelpRating);
63
64 },
65 error: function() {
66 // Do stuff on fail
67 }
68};
69
70// Send AJAX query via jQuery library.
71$.ajax(settings);