You could have a look at this 
-  https://github.com/DonaldMcC/gdms/blob/master/views/default/user.html

It integrates a javascript geolocation plugin to web2py user registration 
and also Leonel Camara's excellent plugin_location_picker which together 
allowed me to do everything I was wanting to do.  Only downside seems to be 
that I think you now need to provide payment details to use Google 
geolocation API's for the mapping piece and address lookup piece  - however 
it is still free for light to moderate use on published websites.

Regards
Donald

On Friday, June 15, 2018 at 2:35:48 PM UTC+1, 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
>
>
>
>

-- 
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