togakangaroo / coa-nolahealth-mobile

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

Geocode clinic locations on the server on import #8

Closed togakangaroo closed 12 years ago

togakangaroo commented 12 years ago

Ok, so I was all set to flip the switch on the distances yesterday when I realized that in order to sort by distance we need the geocoded location of every clinic before we can even call into the distance Matrix.

However, you can only geocode one address at a time. As far as I can tell no service allows you to geocode multiple addresses at one time for free. And you can't issue parallel queries or you get OVER_QUERY_LIMIT back. The guidance is 200ms in between meaning at least 12 seconds to geocode all the clinics. If we want to allow for multiple users at a time then we have to double or triple that number. Even if we use localstorage this is still happening once-per-user.

So the solution as always with scaling problems is to shift read-time to write-time. Meaning that, when they do the initial data import, the ruby code needs to call the google maps api, geocode each address, and serve it as part of the json.

Rob, can you do this? If not, I'm going to be on the phone with some ruby guys this Thursday and they can hopefully help.

PS To get full address c.Street+" "+c.City+" "+c.State+" "c['Zip Code'] seems to be working fine

rcschafer commented 12 years ago

Yeah, I'm going to geocode all of the clinic addresses and add them to the JSON. From that point new addresses will be geocoded as they're added. I mentioned this in #3 so I'm going to close this issue (duplicate.)

rcschafer commented 12 years ago

Actually it makes more sense to keep this as a separate issue since you can't proceed on #3 until I finish this (in other issue tracking systems we could link the two issues as related or depends-upon.) Reopening.

rcschafer commented 12 years ago

@togakangaroo The lat/lngs are now in the JSON as 'lat' and 'lng.'

dlivr8r commented 12 years ago

George, couldn't we just hard code this data after fetching it the once? Then leave it as a thing that Lindsey can change when (and if) she ever has to change a clinic's address? Because of all the data, it strikes me that location would be the least in need of being dynamic. Just a thought.

~Robert

rcschafer commented 12 years ago

Yeah, it's hardcoded in the JSON now. When I hook up the backend Lindsay will be able to add/update clinics and the app will fetch the lat/lng at that time and update the database (which will produce the JSON.)

rcschafer commented 12 years ago

@togakangaroo be warned that there are two clinics (mobile ones) that didn't geocode. They have 0.0 for both lat and lng.