使用Meteor.js将Foursquare API的搜索结果添加到新的Mongo集合中
Upserting Foursquare API venues search results to a new Mongo Collection using Meteor.js
请协助将foursquare的场馆API的结果整理到新的Mongo集合中。下面是我到目前为止写的:
<head>
<title>Places from Foursquare</title>
</head>
<body>
<script src='https://code.jquery.com/jquery-1.11.0.min.js'></script>
<script>
navigator.geolocation.getCurrentPosition(function(data) {
var lat = data['coords']['latitude'];
var lng = data['coords']['longitude'];
var CLIENT_ID = 'MyClientID';
var CLIENT_SECRET = 'MyClientSecret';
var API_ENDPOINT = 'https://api.foursquare.com/v2/venues/search' +
'?client_id=CLIENT_ID' +
'&client_secret=CLIENT_SECRET' +
'&v=20130815' +
'&ll=' + lat + ',' + lng +
'&query=coffee' +
'&callback=?';
Venues = new Mongo.Collection("venues");
Meteor.methods({
'fetchNearbyLocations': function(coords) {
if (Meteor.isServer) {
Venues.upsert(;
});
}
}
});
</script>
</body>
另外,我是否需要在查询工作的任何地方添加API OAuth ?我应该使用。getjson (config。apiUrl +查询API而不是?
谢谢。
您可以使用oleo:foresquare package
然后像这样做。
第一次安装
meteor add oleh:foursquare
第二遍放凭证
//server/secret.js
Foursquare.init({
id: 'xxxxxxxxxxxxxxxxxxxxxxx',
secret: 'xxxxxxxxxxxxxxxxxxxxxxx',
authOnly: false // need auth for using or no?
})
第三次执行场地查询。
<template name="example">
<input type="text" id="venueQuery">
<br>
{{#each venus}}
{{result}}
{{/each}}
</template>
现在JS.
Venus = new Mongo.Collection(null) // client side collection to store the venus
Template.example.events({
'keypress #venueQuery':function(event,template){
if(event.keyCode === 13){
params = { //query to the params,
ll:"35.68949, 139.69171", //Your location use the geo result here
query:template.$('#venueQuery').val(),
limit:10, //the limit of the query
}
//Now the Find.
Foursquare.find(params, function(error, result) {
if(!error){ //if no error
if(result.response.venues.length === 0){ // if the query cant find anything
console.log("nothing find");
}else{
queryResult = result.response.venues //Taking the venues array.
queryResult.forEach(function(venues,index){
street = venues.location.formattedAddress
lat = venues.location.lat
lng = venues.location.lng
city = venues.location.city
venueName = venues.name;
var markerData = {
lat : lat,
lng : lng,
venueName :venueName,
query : params.query,
street : street,
city : city,
}
Venues.insert(markerData) //Inserting into the client side collection
});
}
}
});
}
}
})
源代码演示或在线演示
相关文章:
- 如何组织用户系统的Mongo集合
- Meteor前端未定义Mongo集合
- 在 Meteor React 应用程序中使用 Mongo 集合时,返回一个空数组 []
- 你能存储对 mongo 集合的引用吗?
- 使用 javascript 从 Mongo 集合中查询数据
- 关系问题-Mongo集合和MeteorJS
- 根据日期和其他字段聚合Mongo集合中的数据,并进行计数
- 使用javascript将mongo集合中的所有数据获取到一个文本文件中
- 使用node.js驱动程序将Mongo集合导出到json中
- 为java测试填充mongo集合
- AngularJS meteor mongo集合键值
- 如何使用变量作为键来更新mongo集合
- 如何在javascript中操作返回的mongo集合/游标(meteor.js)
- 在搜索mongo集合时,点符号参数
- 在Meteor中,如何从事件处理程序中创建新的Mongo集合?
- 为什么我无法访问React组件中的Mongo集合
- 无法在node.js中使用mongo访问mongo集合的记录
- Meteor中的Mongo集合正在插入垃圾
- 如何获得关于带有帆的mongo集合中的外部更改的通知
- 简单的todos应用程序教程,试图创建一个函数,从Mongo集合中删除选中的任务