ruby - Get Lat Long from Google -
i want code put location search , return lat , long. using google's geocode api. have code sends request etc., , returns following:
{"results"=>[{"address_components"=>[{"long_name"=>"london", "short_name"=>"london", "types"=>["locality", "political"]}, {"long_name"=>"united kingdom", "short_name"=>"gb", "types"=>["country", "political"]}], "formatted_address"=>"london, uk", "geometry"=>{"bounds"=>{"northeast"=>{"lat"=>51.6723432, "lng"=>0.1478797}, "southwest"=>{"lat"=>51.38494009999999, "lng"=>-0.3514683}}, "location"=>{"lat"=>51.51121389999999, "lng"=>-0.1198244}, "location_type"=>"approximate", "viewport"=>{"northeast"=>{"lat"=>51.6723432, "lng"=>0.1478797}, "southwest"=>{"lat"=>51.38494009999999, "lng"=>-0.3514683}}}, "types"=>["locality", "political"]}], "status"=>"ok"}
i want lat , lng reply above, , assign them 2 variables. appreciated.
h = {"results"=>[{"address_components"=>[{"long_name"=>"london", "short_name"=>"london", "types"=>["locality", "political"]}, {"long_name"=>"united kingdom", "short_name"=>"gb", "types"=>["country", "political"]}], "formatted_address"=>"london, uk", "geometry"=>{"bounds"=>{"northeast"=>{"lat"=>51.6723432, "lng"=>0.1478797}, "southwest"=>{"lat"=>51.38494009999999, "lng"=>-0.3514683}}, "location"=>{"lat"=>51.51121389999999, "lng"=>-0.1198244}, "location_type"=>"approximate", "viewport"=>{"northeast"=>{"lat"=>51.6723432, "lng"=>0.1478797}, "southwest"=>{"lat"=>51.38494009999999, "lng"=>-0.3514683}}}, "types"=>["locality", "political"]}], "status"=>"ok"} lat, lng = h["results"].first["geometry"]["location"].values_at("lat", "lng") lat # => 51.51121389999999 lng # => -0.1198244
Comments
Post a Comment