Sunday, July 1, 2012

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

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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/xdzml63oIzsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment