我正在使用rails对邮政编码进行地理编码。作为测试,我使用了邮政编码60601的代码:
Geocoder.search(60601).first.latitude
字符串然而,这会导致9.42233953846154,这是不正确的。正确的值应该是41.something。所以它是错误的。有没有更好的方法来获得准确的结果?
9.42233953846154
mbskvtky1#
你应该试试,
Geocoder.search(60601)[1].latitude
字符串因为这个特定的“60601”邮政编码在地球上有多个位置,所以你需要从这里的哈希中找到一个特定的地址,当你搜索60601时,你可以检查那里总共有3个位置。
Geocoder.search(60601) => [#<Geocoder::Result::Nominatim:0x00007faaf0440ac8 @cache_hit=nil, @data= {"place_id"=>328970067, "licence"=>"Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", "lat"=>"9.42233953846154", "lon"=>"-84.15445643076923", "class"=>"place", "place_rank"=>21, "importance"=>0.22500009999999993, "addresstype"=>"postcode", "name"=>"60601", "display_name"=>"Quepos, Cantón Quepos, 60601, Puntarenas Province, Costa Rica", "address"=>{"town"=>"Quepos", "county"=>"Cantón Quepos", "postcode"=>"60601", "province"=>"Puntarenas Province", "ISO3166-2-lvl4"=>"CR-P", "country"=>"Costa Rica", "country_code"=>"cr"}, "boundingbox"=>["9.2623395", "9.5823395", "-84.3144564", "-83.9944564"]}>, #<Geocoder::Result::Nominatim:0x00007faaf04407d0 @cache_hit=nil, @data= {"place_id"=>331500121, "licence"=>"Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", "lat"=>"41.838471146546546", "lon"=>"-87.80685671291292", "class"=>"place", "type"=>"postcode", "place_rank"=>21, "addresstype"=>"postcode", "name"=>"60601", "display_name"=>"Riverside, Riverside Township, Cook County, 60601, Illinois, United States", "address"=> {"village"=>"Riverside", "municipality"=>"Riverside Township", "county"=>"Cook County", "postcode"=>"60601", "state"=>"Illinois", "ISO3166-2-lvl4"=>"US-IL", "country"=>"United States", "country_code"=>"us"}, "boundingbox"=>["41.6784711", "41.9984711", "-87.9668567", "-87.6468567"]}>, #<Geocoder::Result::Nominatim:0x00007faaf04404d8 @cache_hit=nil, {"place_id"=>331343428, "licence"=>"Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", "lat"=>"52.41794258392857", "lon"=>"16.910198301785712", "class"=>"place", "type"=>"postcode", "place_rank"=>25, "importance"=>0.12500009999999995, "addresstype"=>"postcode", "name"=>"60-601", "display_name"=>"Sołacz, Poznan, 60-601, Greater Poland Voivodeship, Poland", "address"=>{"suburb"=>"Sołacz", "city"=>"Poznan", "postcode"=>"60-601", "state"=>"Greater Poland Voivodeship", "ISO3166-2-lvl4"=>"PL-30", "country"=>"Poland", "country_code"=>"pl"}, "boundingbox"=>["52.2579426", "52.5779426", "16.7501983", "17.0701983"]}>]
型
omvjsjqw2#
Geocoder.search(60601).map(&:latitude)它将显示列出的纬度数组,结果如下所示[9.42233953846154,41.83832739698795,52.41794258392857]你可以通过传递索引来选择你的纬度。
2条答案
按热度按时间mbskvtky1#
你应该试试,
字符串
因为这个特定的“60601”邮政编码在地球上有多个位置,所以你需要从这里的哈希中找到一个特定的地址,当你搜索60601时,你可以检查那里总共有3个位置。
型
omvjsjqw2#
Geocoder.search(60601).map(&:latitude)
它将显示列出的纬度数组,结果如下所示
[9.42233953846154,41.83832739698795,52.41794258392857]
你可以通过传递索引来选择你的纬度。