Ih all, 

my site do do these operation:


1. geolocalize user in view using html5 navigator.geolocation (classic js 
code)


2. past latitude and longitude to controller with:     
ajax('{{=URL("default","mycoords")}}'+'?lat='+position.coords.latitude+'&lon='+position.coords.longitude,[],':eval');
    mycoords() put coordinates in session.lat e session.lon


3. controller calculate (and insert in db) distance from user position and 
address present in db, using geopy and virtual field:     
db.courses.distance = Field.Virtual('distance', lambda row: 
int(geopy.distance.vincenty((lat,lon),(row.courses.lat,row.courses.lng)).km))


This is ok, but....only after refresh page with F5. (at first page load 
distance is calculated from 0,0 coordinates)

The problem is that controller code is executed before html (and js) in 
view when session.lat e session.lon are None.
Second time, after refresh, session.lat and session.lon, are valorized by 
first execution of html/js and all is ok.

There's a way to run js script before controller code? Or ask coordinates 
from controller to browser directly using python? Or...another solution... 
:-(

Thank!
Fabio



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to