Newbie Q - JSON

The recently released Google maps API v3 returns geocoding info in json format as shown below. I am sure there is an elegant way to extract the lat/lng but I have failed to find it after many attempts - can anyone help? Thanks in advance.

{   "status": "OK",   "results": [ {     "types": [ "point_of_interest", "establishment" ],     "formatted_address": "Buckingham Palace, Westminster, London, UK",     "address_components": [ {       "long_name": "Buckingham Palace",       "short_name": "Buckingham Palace",       "types": [ "point_of_interest", "establishment" ]     }, {       "long_name": "London",       "short_name": "London",       "types": [ "locality", "political" ]     }, {       "long_name": "Westminster",       "short_name": "Westminster",       "types": [ "administrative_area_level_3", "political" ]     }, {       "long_name": "Greater London",       "short_name": "Gt Lon",       "types": [ "administrative_area_level_2", "political" ]     }, {       "long_name": "England",       "short_name": "England",       "types": [ "administrative_area_level_1", "political" ]     }, {       "long_name": "United Kingdom",       "short_name": "GB",       "types": [ "country", "political" ]     } ],     "geometry": {       "location": {         "lat": 51.5007890,         "lng": -0.1422640       },       "location_type": "APPROXIMATE",       "viewport": {         "southwest": {           "lat": 51.4938426,           "lng": -0.1582714         },         "northeast": {           "lat": 51.5077344,           "lng": -0.1262566         }       }     }   } ] }

Hi Henry,

Doesn't include any err testing/checking, but ... you could do something like:

### in some rails project root: $ cat ./tmp/t.runnable def parse_lat_lng(json_str)   lat, lng = [0.0, 0.0]   location = JSON.parse(json_str)['results'][0]['geometry'] ['location']   lat, lng = location['lat'], location['lng']   return [lat, lng] end

Jeff Burlysystems wrote:

Hi Henry, <snip> Jeff

Jeff,

Thanks very much. I had restricted all my searching to from_json.

Henry