i have a form that capture latitude and longitude, and from the latitude 
and longitude value, i want to capture the address info too. check on the 
stackoverflow it can achieved by access url :
http://maps.googleapis.com/maps/api/geocode/json?latlng=lat,lon&sensor=true
is it possible to get json data from url and set as default value of the 
table field?
*e.g.*
*controllers/default.py*
def set_location():
    session.lat = request.post_vars['lat']
    session.lon = request.post_vars['lon']

def test():
table = db.test
if session.lat and session.lon:
table.lat.default = session.lat
table.lon.default = session.lon
fields = None
form = SQLFORM(table, fields = fields)
if form.process(formname = 'form_0').accepted:
current.response.flash = 'form submitted'
elif form.errors:
current.response.flash = 'form has errors'
return dict(form = form)

*models/db.py*
db.define_table('test',
Field('name'),
Field('address', 'text'),
Field('zip_code'),
Field('city'),
Field('country'),
Field('lat', 'double'),
Field('lon', 'double'),
format = '%(name)s')

*views/default/test.html*
{{extend 'layout.html'}}
{{=form}}
<script language="javascript">
function getLocation() {
    navigator.geolocation.getCurrentPosition(postLocation);
}
function postLocation(position) {
    jQuery.post( '{{=URL('set_location')}}',{lat: 
+position.coords.latitude, lon: +position.coords.longitude });
}
function showError() {
  alert("Sorry, no position available.");
}
var geoOptions = {
  enableHighAccuracy: true, 
  maximumAge        : 0, 
  timeout           : 99999999999999
};
getLocation();
</script>

thanks and best regards,
stifan

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