I use pygeocoder.py and something like this!
johnf
class Getlatitudelongitude(dObject):
###############################
# gmaps.py
###############################
import urllib
from time import sleep
import pygeocoder
key = "here_goes_your_key"
def location2latlong(self, query, key="here_goes_your_key" ):
"""pass a complete address
18 Tadlock Place Woodland, CA 95776"""
"""Get the ( latitute, longitude ) coordinates corresponding
to the query. If something goes wrong return None."""
import urllib
from time import sleep
import pygeocoder
#output = 'csv'
#params = { }
### The key below was generated by accessing google
http://code.google.com/apis/maps/signup.html
#params[ 'key' ] =
'ABQIAAAALTR1FL24DycBouLv0t9q3xTEP5gmNW-Z6UMR8J4ewevcZqC8sxRRfI_D2-yrCM4YXmAZEPFdIzSijA'
#key
#params[ 'output' ] = output
#params[ 'q' ] = query
#params = urllib.urlencode( params )
#print params
a_geo_class = pygeocoder.Geocoder()
try:
#f = urllib.urlopen( "http://maps.google.com/maps/geo?%s" %
params )
f = a_geo_class.geocode(query)
response = f.coordinates
latitude = response[0]
longitude = response[1]
#f.close()
return latitude, longitude
except pygeocoder.GeocoderError as err:
return None
On 06/18/2018 10:45 PM, prateek gupta wrote:
Hi All,
I have created a store address form using Django2.0.6+Mysql+Python3.6.
Currently user has to manually fill latitude and longitude for the
store address.
I want to auto-fill both fields once user entered the address.
Below is my current code-
models.py-
|classStore(models.Model):building
=models.ForeignKey(Building,related_name='building',on_delete=models.SET_NULL,blank=True,null=True)name
=models.CharField(max_length=100)postal_code
=models.CharField(max_length=6)address =models.TextField()latitude
=models.FloatField(validators=[MinValueValidator(-90.0),MaxValueValidator(90.0)])longitude
=models.FloatField(validators=[MinValueValidator(-180.0),MaxValueValidator(180.0)])classMeta:managed
=Falsedb_table ='store'|
||
admin.py-
|classStoreAdmin(admin.ModelAdmin):list_display
=('id','name','postal_code','address','latitude','longitude')|
||
Can anyone please help me how to achieve this requirement?
--
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+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@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/56497a07-9c46-4413-9fab-db3f17298146%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/56497a07-9c46-4413-9fab-db3f17298146%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/2ae87e7b-010a-66f1-6292-b20cf70a0ff4%40gmail.com.
For more options, visit https://groups.google.com/d/optout.