From b800a57d28214bbf157e34c355179d88db521d7c Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Fri, 20 Aug 2010 22:22:46 +0000 Subject: [PATCH] Finish tweaking the GeoJSON output and update the docs. --- REST.rdoc | 48 +++++++++++++++++++++++++----------------------- lib/geocoder/us/rest.rb | 5 +++-- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/REST.rdoc b/REST.rdoc index 85aae5a..5c7793c 100644 --- a/REST.rdoc +++ b/REST.rdoc @@ -15,28 +15,35 @@ Parameters: q = a string containing a US street address. -Returns: +Returns a GeoJSON feature collection: { - 'address': '41 Decatur St 94103', - 'results': [ - { 'number': '41', - 'street': 'Decatur St', - 'city': 'San Francisco', - 'state': 'CA', - 'zip': '94103', - 'fips_county': '06075', - 'lat': 37.772502, - 'lon': -122.406032, - 'precision': 'range', - 'score': 0.812 } - ] + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "number": "41", + "street": "Decatur St", + "city": "San Francisco", + "state": "CA", + "zip": "94103", + "fips_county": "06075", + "score": 1.0, + "precision":"range" + }, + "geometry": { + "type": "Point", + "coordinates": [-122.406032, 37.772502] + } + } + ], + "address":"41 Decatur St, San Francisco CA 94103" } -The 'results' list in the returned JSON object contains zero or more addresses -that most closely match the provided string, along with their interpolated -coordinates. Each address result in the list contains the following key/value -pairs: + +Each address match in the feature collection contains some combination of the +following properties: number The building number of the address. When a building number is not @@ -86,8 +93,3 @@ pairs: result, expressed as a float between 0 and 1. A higher score indicates a closer match. Results with a score below 0.5 should be regarded with care. - - lat / lon - The approximate latitude and longitude of the geocoded address or - intersection, given as floating point numbers. - diff --git a/lib/geocoder/us/rest.rb b/lib/geocoder/us/rest.rb index ca55c54..d9a9447 100644 --- a/lib/geocoder/us/rest.rb +++ b/lib/geocoder/us/rest.rb @@ -15,12 +15,13 @@ :properties => result, :geometry => { :type => "Point", - :coordinates => [result[:lon], result[:lat]] + :coordinates => coords } } end { - :type => "FeatureCollection" + :type => "FeatureCollection", + :address => params[:q], :features => features }.to_json else