geocoding - getting latlng from JavaScript, send to server, store into MongoDB

128 views
Skip to first unread message

Markus Gattol

unread,
Jul 2, 2012, 2:26:40 AM7/2/12
to django...@googlegroups.com
Hi folks,

I am using https://github.com/hmarr/mongoengine and Django 1.4 for my current project. MongoDB allows for easy geo queries e.g. you have one latlng and want all other points in your database within a certain radius...  all that's fine and working already.

Now I want to use Google Maps API v3 to do geocoding ie a user inputs an address which I ship off to Google to return with the latlng value to stick into MongoDB so I can do my radius queries (the point I was referring to above). Geocoding is done using JavaScript running on the users browser https://developers.google.com/maps/documentation/javascript/geocoding ie I need to get that latlng info (in a JavaScript variable) from the users browser onto my server and from there into MongoDB. Storing stuff into MongoDB is straight forward, I am not sure about how to get the latlng info onto my server though.

Should I simply issue a HTTP POST from JavaScript or decode to JSON and do an AJAX call to my server? I am no Django expert yet but maybe there is some simpler way to get the latlng information from the JavaScript variable and stick it into a request.POST so I can grab it from within a view (just as you do it with forms)?

Markus Gattol

unread,
Jul 4, 2012, 1:31:26 AM7/4/12
to django...@googlegroups.com
Answering to my own question: this is what I ended up using http://dajaxproject.com/maps/ to send coordinates (latlng) back to the server (from the users browser) and then store it in MongoDB. I can then easily query MongoDB for near points, send the data back to the users browser and draw markers on the map. Good stuff!

Reply all
Reply to author
Forward
0 new messages