作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我知道这不是共享代码的传统方式,但看到堆栈中没有关于如何完成此类任务的任何内容 - 我想我会分享。
为了进一步解释,我到处寻找易于使用的 Node.JS 模块来将地理名称数据处理到 mongo 数据库中。我发现的几个项目最终都失败了。也许人们不分享是因为这真的是一项如此简单的任务。话虽如此,我仍然认为分享我所拥有的东西可能很有值(value)。
以下答案将展示如何处理来自 http://geonames.org 的地名数据变成一个可用的对象,然后可以将其保存到数据库中或直接使用。
最佳答案
var lineReader = require('line-reader');
lineReader.eachLine('./geonames-data/US/US.txt', function(line, last) {
var city = line.split('\t').structure();
if (city.is) { // if this is a city.
// Delete un-needed object properties so we don't add useless info to DB.
delete city.is;
delete city.type;
// Do something with the city object.
console.log(JSON.stringify(city, true, 3) + '\n');
}
});
Array.prototype.structure = function() {
// from geonames readme: - P.PPL populated place a city, town, village, or other agglomeration of buildings where people live and work
return {
_id: Number(this[0]),
name: this[1],
state: this[10],
country: this[8],
coordinates: [this[4], this[5]],
timezone: this[17],
is: ((this[6] == "P") ? true : false), // if object type is city.
type: ((this[6] == "P") ? "city" : "other") // todo: add a parse function to parse other geonames db types
}
}
关于javascript - 如何在 Node.JS 中处理地名城市数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20377896/
我想找到用户在 map 上选择的位置名称。目前我正在获取纬度和经度。但无法获取位置名称。 我正在使用 angularJS 和 angular-google-maps 2.1.5。 这是 html。
例如: 算法目前可以过滤这句话 What is the weather in San Francisco? 对此 什么:代词 是:动词 的:确定者 天气:名词 在:介词 旧金山:地名 我编写的代码
我是一名优秀的程序员,十分优秀!