openstreetmap - Ruby Geocoder 和/或 OpenStreetMap 存在很大的误差
问题描述
我在 Rails 中使用地理编码器 gem 来获取地址的纬度和经度,然后在 OpenStreetMap 中显示它们。
当我搜索我的旧地址时:
>> results = Geocoder.search("1000 Mount Curve Ave E, Altadena, CA 91001")
我得到:
>> results.first.coordinates
=> [34.1976645, -118.1278219]
那些坐标可能在一千英尺之外。(见图。)从谷歌地图得到的准确坐标是 [34.200503,-118.1310407]。
我试过另一个地址,它离得更远,可能有一英里。(1346 E Woodbury Rd,帕萨迪纳,CA 91104)
我已经尝试了另一个地址,它非常准确。(922 E Brockton Ave,雷德兰兹,CA 92374)
有谁知道可能导致这些不准确的原因以及如何始终如一地获得准确的结果?
解决方案
由于 OSM/Nominatim 的不准确和/或限制,我切换到谷歌地图服务。在我的控制器顶部,我添加了:
require 'google_maps_service'
在我的控制器的显示例程中,我最终得到了这个,它产生了准确的结果:
source = Property.find(params[:id])
@property = PropertyDecorator.new(source)
gmaps = GoogleMapsService::Client.new(key: '[removed, put in your own key here]')
results = gmaps.geocode("#{@property.address1} #{@property.address2}")
if results[0] == nil
@lat = 0
@lng = 0
else
@lat = results[0][:geometry][:location][:lat]
@lng = results[0][:geometry][:location][:lng]
end
推荐阅读
- javascript - 如何使用 firestore 读取我的函数?
- amazon-web-services - EC2 实例存储性能下降
- amazon-web-services - Jenkins 与 AWS Fargate 使用 ECS-Fargate 插件
- fedora - Fedora Linux - 无法加载桌面错误 - 无法解析密钥符号 X86FullScreen
- sql - 色调中的奇怪符号
- python - 如果我有 3 个相同长度的值数组,我可以用搅拌机将它们绘制成 3d 吗?有没有一种只使用文本而不使用节点的简单方法?
- php - Laravel 5.8 在提交 ajax POST 时显示 CSRF 令牌不匹配
- javascript - 当数据来自 Javascript 并动态显示时,为什么我不能创建正确的弹性框?
- ssl - 获取桌面应用程序的有效 ssl 证书?
- fonts - 有没有办法在 Pycharm 中支持自定义连字?