I think I have a silly misunderstood with  jQuery.post

I'm trying to store the latitude and longitude in a db.events table. I 
haven't found the right way to do this simple thing,

This is my view: 

{{left_sidebar_enabled,right_sidebar_enabled=False,True}}
{{extend 'layout.html'}}
<h3>View events/entry_event.html</h3>
<script>
  
jQuery.post({'url':'{{=URL('events','entry_event')}}','data':'a='+position.coords.latitude
 
+ "&b" + position.coords.longitude)});
</script>
{{=form}}

{{block right_sidebar}}
{{=A(T("Review events"), _href=URL('events'), _class='button', 
_style='margin-top: 1em;')}}
{{end}}

And this is the controller that does'nt work, of course

@auth.requires_login()
def entry_event():
    """returns a form where we can entry an event"""
    form = crud.create(db.events)
    db.events.latitude=request.post_vars('a')
    db.events.longitude=request.post_vars('b')
    return dict(form=form)

The thing is the event has got several fields you have to fill in the form, 
but the latitude and the longitude are suposed to be parameters we get from 
the browser.

The other way I have tried, but I don't like is, in the model:

    Field('client_ip', default=current.request.client), # then I can use 
GeoIP

Would it be fine to set a default value to the latitude and longitude? How 
could it be? Would it be better than catching it from the browser?

Can you help me please,

Thanks in advance.


El domingo, 21 de octubre de 2012 00:42:15 UTC+2, Michael Gheith escribió:
>
> Hello web2py community!
>
> I have a question:
>
> I know how to get the user's geolocation:
>
> <script>
> if(navigator.geolocation) 
> {
>     navigator.geolocation.getCurrentPosition(printLocation);
>
>     function printLocation(position) 
>     {
>         alert("lat: " +position.coords.latitude + " lon: " + 
> position.coords.longitude);
>     }
> }
> </script>
>
>
> So my question is this:  what's the BEST way to get position.coords.latitude, 
> and position.coords.longitude to a controller function?
>
>

-- 



Reply via email to