Reputation: 176
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.
Upvotes: 1
Views: 1388
Reputation: 5325
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.
Upvotes: 3
Reputation: 18985
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).
Upvotes: 1