Which post code is the nearest with Geokit?

痞子三分冷 提交于 2019-12-11 12:14:00

问题


I'm using geokit to give me distances between two post codes. I need to determine which post code is the nearest.

point_a = Geokit::Geocoders::GoogleGeocoder.geocode "se18 7hp"

alpha = ["cr0 3rl", "W2 1AA"]

miles = alpha.map do |m| point_a.distance_to(m) end

miles.min # => 11.005310790913377

How do I do the reverse of miles.min to get to know which post code was the nearest from point_a?


回答1:


To get the index of an array element, use Array#index

So, in your case, it will be

alpha[miles.index(miles.min)]


来源:https://stackoverflow.com/questions/35635522/which-post-code-is-the-nearest-with-geokit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!