Tuesday, June 19, 2018

Re: How to auto fill latitude and longitude fields in Django2.0.6?

It seems for this I need to use API key from google.
Have you heard about this python package- from location_field.models.plain import PlainLocationField?

I tried with this one but getting some issues-
Issue while using PlainLocationField
On Tuesday, June 19, 2018 at 12:15:54 PM UTC+5:30, johnf wrote:

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-

class Store(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)])    class Meta:      managed = False      db_table = 'store'


admin.py-

class StoreAdmin(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...@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/56497a07-9c46-4413-9fab-db3f17298146%40googlegroups.com.
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+unsubscribe@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/1d9b006f-e1bc-47e5-8812-4841a41c1b86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment