I wanna put res
into an array[google, Rue Abdallaye, null, Trarza, null, 18.0951362, -15.9806735, MR, true]
. How do I do that? Thanks.
>> 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=#开发者_JAVA技巧<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>"
See 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]
You can easily get a hash from a Geokit::GeoLoc object with res.to_hash
, and with res.to_hash.values
you will get an array.
If you are using Ruby 1.9 the hash key order will be preserved, otherwise you should sort the hash by yourself before getting the values into an array.
Bests,
Richard
精彩评论