Edit: Got it working now. The trick is to move the HTTP.get
to the server-side and use the simple:reactive-method
package to get result from a method.
I could use some help figuring out how to display the result of Meteor.HTTP.Get. The docs are sketchy and there's no topics here that relates to my case.
I'm searching Foursquare to find local farmers & markets around you. then display the result in a map (no map yet). Here's the code:
The start page:
<template name="locator">
<a class="button" href="{{pathFor route='locatorMap' query='group=farmers'}}">Farmers</a>
<a class="button" href="{{pathFor route='locatorMap' query='group=markets'}}">Markets</a>
</template>
The soon-to-be map page. Edited: Mar 31, 2015
<template name="locatorMap">
<div class="list">
{{#each venues}}
<p>{{name}}. {{location.lat}}, {{location.lng}}</p>
{{/each}}
</div>
</template>
The routing (lib/router.js)
Router.route('/locator', {name: 'locator'});
Router.route('/locator/map', {name: 'locatorMap'});
The helper (client/locator/locator.js). Edited: Mar 31, 2015
// A static list of venue categories
Foursquare.categoryId = { ... };
Template.locatorMap.helpers({
venues: function() {
var search_group = Router.current().params.query.group;
var search_categories = Foursquare.categoryId[search_group].join(',');
var search_location = Geolocation.latLng();
if (search_location) {
// using simple:reactive-method
return ReactiveMethod.call('FoursquareSearch', search_categories, search_location);
} else {
throw new Meteor.Error("No Location", "Failed to get ...");
}
}
});
The method (server/methods/foursquare.js). Edited: Mar 31, 2015
Meteor.methods({
FoursquareSearch: function(categories, location) {
check(categories, String);
check(location, Object);
try {
var search_result = HTTP.call(
'GET', 'https://api.foursquare.com/v2/venues/search?',
{
timeout: 5000,
params: { ... }
}
);
return search_result.data.response.venues;
} catch (_error) {
throw new Meteor.Error("No Result", "Failed to fetch ...");
}
}
});
I can see data on the console. But i'm just not sure how how to pass it into a template helper. If you guys need more info, just let me know.
Any help is appreciated. Thx!