城市/国家文本字段验证
我需要跟踪我的应用程序的用户 lat/lng/city/country ,并满足以下两个要求:
1)自动获取用户 lat/lng/city/country 。 (这很简单,我可以使用ip,或者如果他们有支持地理定位的浏览器,那就更好了)。
2) 允许用户自定义此位置(也许 IP 地址查找没有给出准确的城市)。该位置是一个自由格式的文本字段(不是下拉列表)。当用户输入新位置时,应根据可用城市/国家对其进行验证。如果它针对其中任何一个进行验证,请选择它,然后检索新位置的经纬度。 (这就是我遇到的问题)
另外需要澄清的是,这是一个使用 MongoDB 的 Rails 3 应用程序。我正在寻找一个 API 或数据库来允许我同时完成 (1) 和 (2) 的任务。有人做过类似的事情吗?寻找一些关于其他人如何做到这一点的想法。
I need to keep track of the users lat/lng/city/country for my application with the following two requirements:
1) Get the users lat/lng/city/country automatically. (This is easy, I can use the ip or if they have a browser that supports geolocation, even better).
2) The user is allowed to customize this location (maybe the ip address lookup didn't give an accurate city). The location is a freeform text field (not a dropdown). When the user enters a new location it should be validated against available cities/countries. If it validates against any one of them, select it and then retrieve the latlng for the new location. (This is what I'm having trouble with)
Also to clarify, this is a Rails 3 app using MongoDB. I am looking for either a single API or database that would allow me to do both (1) and (2). Has anyone done anything similar? Looking for some ideas as to how others have done this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题并不完全清楚您遇到了什么问题。一般来说,我会这样做:
您可以使用 Google 的地理编码 API 查找未知位置的坐标。
Your question isn't entirely clear as to what problem you are having. In general terms, I would do it like this:
You could use Google's Geocoding API to look up the coordinates of unknown locations.
我会推荐 Geokit Gem,它在为多个项目提供前端方面做得非常好地理编码 API。我强烈建议坚持使用雅虎或谷歌,只是为了纯粹的数据完整性问题。
有一个 rails 插件,它为 Activerecord 添加了一些不错的助手。目前,主要项目与 Rails 3 不兼容,但至少有一个分支已针对 Rails 3 进行了更新。
I would recommend the Geokit Gem, it does a very nice job of providing a front end for several Geocoding APIs. I highly recommend sticking with Yahoo or Google, just for sheer data integrity issues.
There is a rails plugin, that adds some nice helpers to Activerecord. At the moment the main project is not rails 3 compatible, but there is at least one fork that has updated for rails 3.