OK, I have a workable solution. I generate a checkin form and it calls 
navigator.geolocation. If it succeeds, I render the map (the user is 
assured that the location is the right one) and I pass the position 
parameters to a cookie. The page in which the map is rendered has a link to 
a controller to finish the checkin process and the controller parses the 
cookie data to latitude and longitude floats, which is what I need.

This is not ideal but quite usable. Right now the link to finish the 
checkin is rendered before navigator.geolocation is finished and the map is 
rendered. I have to add wording to wait until the map loads before clicking 
the link. Not pretty! It is especially not pretty in Firefox,where 
navigator.geolocation sometimes takes a very long time to execute (why?). 
Ideally the link to finish should appear only after the the location is 
determined and the map displayed. 

The code is messy now (lots of experimental stuff strewn throughout), and I 
will clean it up and then post what I have. I am sure others will find 
better solutions. At least for now, I will enjoy SXSW  a lot more  :-)

On Friday, February 28, 2014 11:47:44 AM UTC-8, Ephraim Feig wrote:
>
> 0 down vote 
> favorite<http://stackoverflow.com/questions/22102460/page-does-not-update-after-navigator-geolocation-call-in-rails-check-in-check#>
>  
>   
> I am using standard HTML5 location services. A user comes into a cafe, 
> opens the app, clicks on "Check-in!" and the app gets the location and uses 
> it until the user later clicks "Check-out!". 
>
> In my viewer, I call on a script containing navigator.geolocation and it 
> does its job. I successfully pass the latitude and longitude parameters to 
> my controller and it updates everything. But when all is done and I 
> redirect_to root_url, the new page does not refresh (I know at some point I 
> should do it more elegantly and just update the link part, but for now, I 
> just want to get this going and understand what is going on). Here is my 
> code:
>
> In my viewer-
>
>  <% if (@voterinfo.checkin == 0) %>
>               <li>
>                 <h4>    <%= link_to "-->Check-In!", "#", :id => 'findMe' %>   
>    </h4>
>                 <script>
>                   $(function(){
>                      $("a#findMe").click(function(){
>                          if (navigator.geolocation) {
>                              
> navigator.geolocation.getCurrentPosition(function (position) {
>                                  $.post('/users/set_geolocation/', {latitude: 
> position.coords.latitude,
>                                              longitude: 
> position.coords.longitude,
>                                              dataType: 'float'});
>                              }, function () {
>                                  alert('We couldn\'t find your position.');
>                              });
>                          } else {
>                              alert('Your browser doesn\'t support 
> geolocation.');
>                          }
>                       });
>                   })
>                 </script>
>                </li>
>           <% else %>
>               <li> <h4><%= link_to "--->CHECK-OUT!", :controller => :users,
>                                    :method => :set_geolocation %></h4></li>
>           <% end %>
>         </ul>
>   <% end %>
>
> And here is the relevant part of my users_controller-
>
>  def set_geolocation
>   @user = current_user
>   @voterinfo = Voterinfo.find_by_user_id(@user.id)
>   if (@voterinfo.checkin == 0)
>     @user.update_attributes(:longitude => params['longitude'], :latitude => 
> params[:latitude])
>     @user.save(validate: false)
>     sign_in(@user)
>     @voterinfo.checkin = 1
>     @voterinfo.save
>     redirect_to root_url
>   else
>    @voterinfo.checkin = 0
>    @voterinfo.save
>    redirect_to root_url
>   end
>
> end
>
> Thank you for any help here.
>
>
>

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to