Which post code is the nearest with Geokit?

2019-08-14 15:12发布

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?

标签: ruby geokit
1条回答
狗以群分
2楼-- · 2019-08-14 16:13

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

So, in your case, it will be

alpha[miles.index(miles.min)]
查看更多
登录 后发表回答