使用 Faker gem 使用 Ruby on Rails 为 Google 地图生成有效地址

发布于 2024-11-05 06:07:44 字数 240 浏览 0 评论 0原文

我正在使用很棒的 FAKER gem 生成数千(或数十万)种子数据(或更准确地说用测试数据填充数据库),所以我不想手动执行某些操作。

因为我使用谷歌地图,它会自动对每个地址进行地理编码。如果我能够生成有效的测试数据,那就太好了。不幸的是,FAKER 是……假的。我可以关闭地理编码,但我想要有效的测试数据。

有谁知道一种方法来生成随机的、假的(嗯......不是假的)地址,这些地址将被正确地进行地理编码。

提前致谢。

I am generating seed data (or more accurately populating the database with test data) using the awesome FAKER gem for thousands (or hundreds of thousands) so something I don't want to do manually.

Because I am using google maps, it is automatically geocoding each address. It would be great if I could generate test data that was valid. Unfortunately, FAKER is well... fake. I could turn off the geocoding, but I would like valid test data.

Does anyone know a way to generate random, fake (well... not fake) addresses that will properly be geocoded.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔嚣张 2024-11-12 06:07:44

我在这里找到了所有这些以及更多内容:
http://www.fakenamegenerator.com/free-tools.php

我正在寻找这样的发电机可以限制在特定的城市。他们无法做到这一点(据我所知),但可以使用全国范围的数据和多个国家/地区的数据。

但由于该链接对我不起作用,我最终使用了反向逻辑。我在我想要测试的区域生成了随机坐标,并向 Google 询问了地址。许多人没有地址,但对于那些有地址的人,我有一堆有效地址,正好位于我想要的位置。如果您对地址进行地理编码,通常不会得到相同的坐标,但它们应该非常接近,这有助于简单的大致验证。

I found all that and more here:
http://www.fakenamegenerator.com/free-tools.php

I was looking for such a generator that could be restricted to a specific city. They can't do that (from what I can tell) but country wide data and multiple countries is available.

But because that link didn't work for me I ultimately used reverse logic. I generated random coordinates in the area I wanted to test and asked Google for the address. Many had no address but for those that did I had a bunch of valid addresses in precisely the locations I wanted. If you then geo-code the address you will not usually get the same coordinates back but they should be really close which makes for simple ball-park validation.

走过海棠暮 2024-11-12 06:07:44

访问您当地的县评估区网站并获取他们的数据。 (或者找一个更大的区让你下载)

然后从那里导入(实际地址),而不是用faker来弥补

Go to your local county-assessment-district website and pull down their data. (or find a larger district that lets you download)

Then import from there (actual addresses), rather than using faker to make them up

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文