Skip to content

Instantly share code, notes, and snippets.

@tazjel
Forked from mattspence/web2py geolocate
Last active August 29, 2015 14:07
Show Gist options
  • Save tazjel/b6f99b0d0016d0bdc343 to your computer and use it in GitHub Desktop.
Save tazjel/b6f99b0d0016d0bdc343 to your computer and use it in GitHub Desktop.
controller:
def index()
return dict(latitude=session.latitude, longitude=session.longitude)
def set_location():
session.latitude = request.vars.lat
session.longitude = request.vars.lng
default/index.html:
{{extend 'layout.html'}}
{{if not session.latitude:}}
<script>
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(postLocation);
function postLocation(position)
{
jQuery.post( '{{=URL('set_location')}}',{lat: +position.coords.latitude, lng: +position.coords.longitude });
}
}
</script>
{{pass}}
{{if 'latitude' in globals():}}
<p>
Lat: {{=latitude}}
</p>
<p>
Lng: {{=longitude}}
</p>
{{pass}}
{{=response.toolbar()}}
{{if 'message' in globals():}}
<h3>{{=message}}</h3>
{{elif 'content' in globals():}}
{{=content}}
{{else:}}
{{=BEAUTIFY(response._vars)}}
{{pass}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment