togakangaroo / coa-nolahealth-mobile

Code For America HackDay Nola Health Mobile app
3 stars 3 forks source link

Rank search results by distance #3

Closed rcschafer closed 12 years ago

rcschafer commented 12 years ago

If an address is entered for a search rank results by distance. Distance can be obtained via the GMaps V3 Geocoding and Distance Matrix APIs.

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 to minimize calls to the GMaps API.

togakangaroo commented 12 years ago

looking stuff up. Need to use localStorage with this so the service is not just constantly getting hammered

rcschafer commented 12 years ago

Good idea, store the lat/lng of the address the user entered. I guess we still have to hit the DistanceMatrix service once for every provider so you can rank the search results correctly but we can cache those too.

rcschafer commented 12 years ago

We could do a quick-and-dirty approach that calculates the actual distance between the clinic and the provided address; this wouldn't involve the Google DistanceMatrix service so we'd only need to do a single geocoding call. There's some formulas for calculating this distance here.

togakangaroo commented 12 years ago

I'll get this implemented by wednesday. I was actually browsing the google api and the distance matrix takes textual addresses as parameters, there is no need to geolocate anything at all!