作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试遵循此处给出的 Amazon DynamoDB 地理库的非常基本的教程 https://www.npmjs.com/package/dynamodb-geo .即使按照链接中提到的步骤进行操作,我的 myGeoTableManager.queryRadius() 调用也没有给我任何结果。以下是我遵循的步骤。
我用下面的脚本创建了 dynamoDB 表
require("dotenv").config();
var AWS= require('aws-sdk');
AWS.config.update({accessKeyId: process.env.accessKeyId, secretAccessKey: process.env.secretAccessKey, region: "us-east-1"});
const ddb = new AWS.DynamoDB();
const ddbGeo = require('dynamodb-geo');
const config = new ddbGeo.GeoDataManagerConfiguration(ddb, 'locationData');
config.hashKeyLength = 5;
const createTableInput = ddbGeo.GeoTableUtil.getCreateTableRequest(config);
// Tweak the schema as desired
createTableInput.ProvisionedThroughput.ReadCapacityUnits = 5;
console.log('Creating table with schema:');
console.dir(createTableInput, { depth: null });
// Create the table
ddb.createTable(createTableInput).promise()
// Wait for it to become ready
.then(function () { return ddb.waitFor('tableExists', { TableName: 'locationData' }).promise() })
.then(function () { console.log('Table created and ready!') });
然后我使用以下脚本在 dynamoDB 中插入和查询数据。
require("dotenv").config();
var AWS= require('aws-sdk');
AWS.config.update({accessKeyId: process.env.accessKeyId, secretAccessKey: process.env.secretAccessKey, region: "us-east-1"});
const ddb = new AWS.DynamoDB();
const ddbGeo = require('dynamodb-geo');
const config = new ddbGeo.GeoDataManagerConfiguration(ddb, 'locationData');
config.hashKeyLength = 5;
const myGeoTableManager = new ddbGeo.GeoDataManager(config);
myGeoTableManager.putPoint({
RangeKeyValue: { S: '1234' },
GeoPoint: {
latitude: 28.749472,
longitude: 77.056534
},
PutItemInput: {
Item: {
country: { S: 'country1' },
capital: { S: 'capital1' }
},
}
}).promise()
.then(function() { console.log('Insert Done!') });
myGeoTableManager.putPoint({
RangeKeyValue: { S: '5678' },
GeoPoint: {
latitude: 28.749999,
longitude: 77.056999
},
PutItemInput: {
Item: {
country: { S: 'country2' },
capital: { S: 'capital2' }
},
}
}).promise()
.then(function() { console.log('Insert Done!') });
myGeoTableManager.queryRadius({
RadiusInMeter: 100000,
CenterPoint: {
latitude: 28.749888,
longitude: 77.056888
}
}).then((locations) => {
console.log(locations);
});
即使纬度和经度完全相同,myGeoTableManager.queryRadius() 也会给我空响应。
最佳答案
有更新版本 https://github.com/renet/dynamodb-geo-v3
可用,支持 AWS 3.* 版本。
关于node.js - 无法在 Node 中使用 GeoDataManager 查询 dynamoDb 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63429443/
我正在尝试遵循此处给出的 Amazon DynamoDB 地理库的非常基本的教程 https://www.npmjs.com/package/dynamodb-geo .即使按照链接中提到的步骤进行操
我是一名优秀的程序员,十分优秀!