Re: saving latitude and longitude values in django

3,369 views
Skip to first unread message

Doug Snyder

unread,
Jun 4, 2013, 9:08:05 AM6/4/13
to django...@googlegroups.com
I think you'd at least want to use either a DecimalField or FloatField for the lat & long numbers.
There's a nice GIS package in django called GeoDjango, it has lots of built in functionality for all kinds of geographical things.
This may be over kill for your application but I thought I'd let you know it exists.
One thing it allows you to do is query the DB based on location, i.e. distance between points with lat & long.
You could compute this using a standard norm calculation but its slow compared to using a native DB query.


On Tue, Jun 4, 2013 at 8:49 AM, Sivaram R <sivar...@gmail.com> wrote:
models.py

class Geolocation(models.Model):
    user = models.ForeignKey(User, null=False)
    location_latitude = models.CharField('Latitude', max_length=20, null=True, blank=True)
    location_longitude = models.CharField('Longitude', max_length=20, null=True, blank=True)

In my application,i am using google map using Javascript.Latitude and longitude values are displayed in map using marker,i need to get both values from map and save to database using Python.

1.I want to know how to get the values from map and save.

2.How to right view function and form.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sivaram R

unread,
Jun 4, 2013, 9:42:05 AM6/4/13
to django...@googlegroups.com
Can i get any post or example related to this.

Thanks

Vernon D. Cole

unread,
Jun 4, 2013, 12:06:17 PM6/4/13
to django...@googlegroups.com

Saving the values is the easy part.  The format you use depends on what you want to do with them.  If you are only displaying them to users, CharField might be okay.  If you are going to do any processing, you should probably convert them.  My storage is done like this:

    gpsLatitude = models.FloatField("Latitude", blank=True, null=True,
        help_text="degrees, floating point, South is negative")
    gpsLongitude = models.FloatField("Longtitude", blank=True, null=True,
        help_text="degrees, floating point, West is negative")

Getting the values may be a problem. I do not understand what you mean by "displayed in map using marker".  Is what you have is a graphical image with a marker icon somewhere on it?  Or are you using a Google api which  can be asked to give you more information?
--

roopas...@gmail.com

unread,
Jun 4, 2013, 12:25:17 PM6/4/13
to django...@googlegroups.com
Vermon D. Cole,How to get the latitude and longitude from javascript(using javascript map) and save it to database in Django.If marker is placed  in any place,it will show/display the longitude and latitude value,need to get that and save in in db.Hope this clear.

Thanks

Derek

unread,
Jun 5, 2013, 3:37:21 AM6/5/13
to django...@googlegroups.com
Your question seems to be more about using javascript with Django; have a look at this Q&A:
http://stackoverflow.com/questions/5735107/basic-django-and-javascript-question
There is also a lonk to a downloadable sample app.

The "getting the values from the map via javascript" is a different kind of problem altogether; you'd need to ask about that on a javascript forum.

Derek

unread,
Jun 5, 2013, 4:42:26 AM6/5/13
to django...@googlegroups.com
Also: just came across this mapping example, using Leaflet, and a standards-based approach (POST via WFS) to write point data from the map to a database:

http://blog.georepublic.info/2012/leaflet-example-with-wfs-t/
https://github.com/Georepublic/leaflet-wfs/blob/master/index.html#L201  (POST code)
Reply all
Reply to author
Forward
0 new messages