togakangaroo/coa-nolahealth-mobile — Issue #3: Rank search results by distance
Author: rcschafer
Created: 2012-02-27 06:01:23+00:00
State: open

If an address is entered for a search rank results by distance. Distance can be obtained via the GMaps V3 [Geocoding](http://code.google.com/apis/maps/documentation/javascript/geocoding.html) and [Distance Matrix](http://code.google.com/apis/maps/documentation/javascript/distancematrix.html) APIs.

[gmaps.js](https://github.com/togakangaroo/coa-nolahealth-mobile/blob/master/app/assets/javascripts/gmaps.js) contains an initial implementation of `get_distance(origin_address, destination_address)` but the GMaps calls are asynchronous so we'll have to implement a version that takes a callback method so the main GUI can 'wait' for values to return before sorting and presenting the results.

The provider (destination) addresses are known so we can geocode them in advance and add the lat/lng to the [JSON data](http://code.google.com/apis/maps/documentation/javascript/distancematrix.html) to minimize calls to the GMaps API.