我想把res
放到array[google, Rue Abdallaye, null, Trarza, null, 18.0951362, -15.9806735, MR, true]
中。我怎么做呢?谢谢。
>> puts res
Provider: google
Street: Rue Abdallaye
City:
State: Trarza
Zip:
Latitude: 18.0951362
Longitude: -15.9806735
Country: MR
Success: true
=> nil
>> res.kind_of?(Array)
=> false
>> res.inspect
=> "#<Geokit::GeoLoc:0x1021f10c8 @city=nil, @province="Nouakchott", @country="Mauritania", @street_address="Rue Abdallaye", @suggested_bounds=#<Geokit::Bounds:0x101f9f8d8 @ne=#<Geokit::LatLng:0x101f9f748 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x101f9f810 @lng=-15.9820212, @lat=18.0937799>>, @country_code="MR", @state="Trarza", @all=[#<Geokit::GeoLoc:0x1021f10c8 ...>, #<Geokit::GeoLoc:0x101f9f5e0 @city="Nouakchott", @province=nil, @country="Mauritania", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x101d624a8 @ne=#<Geokit::LatLng:0x101d62458 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x101d62480 @lng=-15.9820212, @lat=18.0937799>>, @country_code="MR", @state="Nouakchott", @all=[#<Geokit::GeoLoc:0x101f9f5e0 ...>], @accuracy=4, @lng=-15.9993672, @full_address="Tevragh Zeina, Nouakchott, Mauritania", @provider="google", @precision="city", @zip=nil, @lat=18.110344, @success=true>, #<Geokit::GeoLoc:0x101d62048 @city="Nouakchott", @province=nil, @country="Mauritania", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x101506f70 @ne=#<Geokit::LatLng:0x101506ef8 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x101506f20 @lng=-15.9820212, @lat=18.0937799>>, @country_code="MR", @state="Nouakchott", @all=[#<Geokit::GeoLoc:0x101d62048 ...>], @accuracy=4, @lng=-15.97842, @full_address="Nouakchott, Mauritania", @provider="google", @precision="city", @zip=nil, @lat=18.084061, @success=true>, #<Geokit::GeoLoc:0x1015069d0 @city=nil, @province="نواكشوط", @country="Mauritania", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x101274e10 @ne=#<Geokit::LatLng:0x101274c58 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x101274de8 @lng=-15.9820212, @lat=18.0937799>>, @country_code="MR", @state="ولاية الترارزة", @all=[#<Geokit::GeoLoc:0x1015069d0 ...>], @accuracy=3, @lng=-15.92299, @full_address="Nouakchott, Mauritania", @provider="google", @precision="state", @zip=nil, @lat=18.1801386, @success=true>, #<Geokit::GeoLoc:0x101274af0 @city=nil, @province=nil, @country="Mauritania", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x1005b4658 @ne=#<Geokit::LatLng:0x1005b4608 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x1005b4630 @lng=-15.9820212, @lat=18.0937799>>, @country_code="MR", @state="Nouakchott", @all=[#<Geokit::GeoLoc:0x101274af0 ...>], @accuracy=2, @lng=-15.92299, @full_address="Nouakchott, Mauritania", @provider="google", @precision="state", @zip=nil, @lat=18.1801386, @success=true>, #<Geokit::GeoLoc:0x1005b41d0 @city=nil, @province=nil, @country="Mauritania", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x10349e040 @ne=#<Geokit::LatLng:0x10349dff0 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x10349e018 @lng=-15.9820212, @lat=18.0937799>>, @country_code="MR", @state=nil, @all=[#<Geokit::GeoLoc:0x1005b41d0 ...>], @accuracy=1, @lng=-10.940835, @full_address="Mauritania", @provider="google", @precision="country", @zip=nil, @lat=21.00789, @success=true>], @accuracy=6, @lng=-15.9806735, @full_address="Rue Abdallaye, Nouakchott, Mauritania", @provider="google", @precision="zip+4", @zip=nil, @lat=18.0951362, @success=true>"
参见http://geokit.rubyforge.org/api/geokit-gem/Geokit/GeoLoc.html
ary = [res.provider, res.street_name, res.city, res.state, res.zip, res.lng, res.lat, res.country_code, res.success]
您可以轻松地从Geokit::GeoLoc对象与res.to_hash
中获得散列,并与res.to_hash.values
您将获得一个数组。
如果你使用Ruby 1.9,哈希键顺序将被保留,否则你应该在将值放入数组之前自己对哈希进行排序。
最好地,
理查德