views:

183

answers:

2

Hello,

So i am writing a little app that compares a user's position against a database on web-based server written using Django and performs some functions with it.

Accessing the browser's geolocation data (in supported browsers ) is fairly trivial using JavaScript. But what is the best way to allow the Django server to access the longitude and latitude variables? Is it best to wrap them up as a JSON object and send to the server via POST? Or is there some easier (Geo)Django-based way to access the Navigator.geolocation browser object.

Please forgive a newbie a question like this, but my Google-Fuing only seems to find ways to insert variables into JavaScript via template tag, whereas I need it to work the other way!

Any advice or code snippets greatly appreciated. Feel free to talk to me like I am an idiot.

+1  A: 

Navigator.geolocation is only available on the client side. You'll have to send the data back to the server using Javascript, such as via a POST (as you surmised).

kevingessner
+1  A: 

You will indeed need to POST your location data to a Django view.

If all you need is simple distance calculations, take a look at Geopy.

If you want to interact with the ORM and filter/search based on location, you'll want to look at GeoDjango.

Harold