Hi Dave!
I will try your solution. I had not thought to using this metod.

Thanks!
Fabio


Il giorno venerdì 15 giugno 2018 22:12:26 UTC+2, Dave S ha scritto:
>
>
>
> On Friday, June 15, 2018 at 6:35:48 AM UTC-7, Fabio Ceccarani wrote:
>>
>> 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
>>
>>
> I'd look at using the LOAD() helper or the ajax() function.  With these, 
> the page will load, the JS will run, and then you'll fetch the distance as 
> an automatic update.  You'll break your controller up so that one function 
> gives you the page load, and the other function does the calculation.
>
> <URL:
> http://web2py.com/books/default/chapter/29/12/components-and-plugins#LOAD>
> <URL:
> http://web2py.com/books/default/chapter/29/11/jquery-and-ajax#The-ajax-function
> >
>  
> /dps
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to