snebel/Citibike — pull request #1 by bswinnerton (2013-11-06 20:40:52+00:00)
Title: Immediate HTML5 location detection

Okay, so while I don't think this is the worlds most elegant solution, it's the best I could come up with at work.

Here's the way it works:

1. The user hits a new root url. The controller action of this new root checks to see if `cookies['lat_lng']` exists, if it does, it passes it on to the next page. If it doesn't, the new action's view is rendered, and the javascript is processed.
2. Inside of the javascript, we ask for the user's location in the `handleGeolocation` callback. The user has to accept the location sharing, if they don't they're stuck at that view. I'd add some sort of error handling here in the event they decide they don't want to share their location.
3. If the user does decide to share the location, we use javascript or redirect them to the original `Trip#new` action, at which point they'll have the cookie.

One thing I just thought of that I don't have time to fix: if a user goes straight to `/trips/new` without first going to `/trips/set_location`, they won't have the current location. Make a check in the `Trip#new` action to see if the cookie exists, and if it doesn't, pass them to the `Trip#set_location` action (which will then in turn pass them back to `Trip#new`.

Hope this helps, and feel free to stop by tonight if you want to talk this out.