How to fill latitude and longitude values from an existing location field in Django+Python?

327 views
Skip to first unread message

prateek gupta

unread,
Jun 21, 2018, 6:43:45 AM6/21/18
to Django users
Hi All,

I need your help in one task.
I have created a address form in Django 2.0.6 + Python3.6.
In this form once user entered the address, the location field is auto filled with latitude,longitude as below screen shot-


Now I want to write a python function which can fetch Latitude and Longitude values from the Location field and can save them in respective Latitude/Longitude fields.

My models.py code is as below:
class Store(models.Model):
    postal_code = models.CharField(max_length=6)
    address = models.TextField()
    location = PlainLocationField(based_fields=['address'], zoom=7, null=True)
    phone = models.CharField(max_length=60, blank=True, null=True)
    latitude = models.FloatField()
    longitude = models.FloatField()
    class Meta:
        managed = False
        db_table = 'store'

admin.py:
class StoreAdmin(admin.ModelAdmin):
list_display = ('postal_code', 'address','phone', 'latitude', 'longitude')

Can anyone help me to achieve this functionality?

Jason

unread,
Jun 21, 2018, 8:01:13 AM6/21/18
to Django users
You've been posting here about this regularly (at least four times) with no responses.  I don't think anyone here knows how to solve your problem.  what else have you looked at?  eg, have you asked on stack overflow or other places?

prateek gupta

unread,
Jun 21, 2018, 8:29:17 AM6/21/18
to Django users
Got it Jason, I will not post anymore now.

Julio Biason

unread,
Jun 21, 2018, 8:34:32 AM6/21/18
to django...@googlegroups.com
Hi Prateek.

You're using Google Maps for the lat/long, right?

In this case, I'd suggest that, on the function you receive the data and update the field, you also make a request to some URL to update the lat/long of the current displayed object.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2c6cc9f6-1455-439c-ad78-459fcc1828ab%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

Melvyn Sopacua

unread,
Jun 21, 2018, 8:46:00 AM6/21/18
to django...@googlegroups.com
On donderdag 21 juni 2018 14:29:17 CEST prateek gupta wrote:
> Got it Jason, I will not post anymore now.

Well, not the same question at least. The second one was better, since it was
specific. What you're asking with this question is too broad and doing it on
stackoverflow will yield the same results.

You're basically asking us to code it for you, because you have a deadline
and not enough understanding of Django or it's eco system. There are a lot of
helpful people on this list, but if you want this done on the short term, you
can enlist someone to tutor you or cooperate on the project with you.
Naturally, you should offer some incentive to people as this isn't a simple
Question & Answer problem.

--
Melvyn Sopacua

Jason

unread,
Jun 21, 2018, 9:24:55 AM6/21/18
to Django users
Uh, that's not what I mean.  You had asked this question multiple times and gotten no response back.  If you're relying on this group for your only source of help, that means you lost quite a bit of time getting this done.  Where else were you looking?  What other options did you try to use?

prateek gupta

unread,
Jun 21, 2018, 9:53:40 AM6/21/18
to Django users
Thanks for your reply.
I was trying to first use in built django library for that https://github.com/caioariede/django-location-field
It is showing me a map with location field(conaining latitude,longitude)
But I want to save the latitude/longitude values in DB so I am not seeing any way in this inbuild library.

Now I will try Google API.


On Thursday, June 21, 2018 at 6:04:32 PM UTC+5:30, Julio Biason wrote:
Hi Prateek.

You're using Google Maps for the lat/long, right?

In this case, I'd suggest that, on the function you receive the data and update the field, you also make a request to some URL to update the lat/long of the current displayed object.
On Thu, Jun 21, 2018 at 9:29 AM, prateek gupta <gupt...@gmail.com> wrote:
Got it Jason, I will not post anymore now.

On Thursday, June 21, 2018 at 5:31:13 PM UTC+5:30, Jason wrote:
You've been posting here about this regularly (at least four times) with no responses.  I don't think anyone here knows how to solve your problem.  what else have you looked at?  eg, have you asked on stack overflow or other places?

--
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 https://groups.google.com/group/django-users.

Matthew Pava

unread,
Jun 21, 2018, 10:11:22 AM6/21/18
to django...@googlegroups.com

Based on the information of that project, it does not support Django passed version 1.10.  What version are you using?

Saving of the location should be automatic based on my understanding of that package.

You may want to contact the author of that package to get more help.

Jani Tiainen

unread,
Jun 21, 2018, 10:28:42 AM6/21/18
to django...@googlegroups.com
Hi,

First I really suggest you to take a look at Django GIS functionality. It requires few libs to be installed but gives you tons of functionality. Including fields that can show geometry on map.

Next problem is that you want to convert physical address to coordinates. Process is called geocoding and there exists several services and libraries you can use.

Finally the hard part - just combine those two and you get what you're asking for.


--
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 https://groups.google.com/group/django-users.

prateek gupta

unread,
Jun 21, 2018, 11:31:45 AM6/21/18
to Django users
I am using Django 2.0.6 and yes I am able to use this package .
This package is currently showing a map below the address and once I enter the address; it fill the location field and changes the map according.

To post to this group, send email to djang...@googlegroups.com.

Himanshu Gamit

unread,
Jun 21, 2018, 2:22:55 PM6/21/18
to django...@googlegroups.com

Prateek,

 

Have you tried this module? http://django-map-widgets.readthedocs.io/en/latest/

 

Thanks

Himanshu

Sent from Mail for Windows 10

prateek gupta

unread,
Jun 22, 2018, 4:13:49 AM6/22/18
to Django users
They have mentioned that it is for Django PostGIS fields.
Reply all
Reply to author
Forward
0 new messages