I can see several causes here why you're not getting the desired result. The biggest one is you declare fnclatitude as taking a single argument, called location - but when you call the function from your save() method you're passing no arguments to it.
Second, you're returning element 3 (which is longitude) and calling it latitude. There are two possible ways to rewrite the code to work: 1: (bring the call to Google into the save() method, which is perfectly acceptable if this is the only model that requires geocoding) Code at: http://dpaste.com/91472/ 2: (keep it seperate, which is more useful if other models in your system will require geocoding. I'd definitely rename the function though because it's doing more than just returning latitude at that point.) Code at: http://dpaste.com/91483/ Adam On Mon, Nov 17, 2008 at 3:19 AM, please smile <[EMAIL PROTECTED]> wrote: > HI All, > > How can I add automatically latitude and longitude of the physical address. > for exp if, fnclatitude('Chennai') returns latitude and longitude of > chenai. > > Please help > > This is my model (models.py) > > def fnclatitude(location): > key = settings.GOOGLE_KEY > output = "csv" > location = urllib.quote_plus(location) > request = "http://maps.google.com/maps/geo?q=%s&output=%s&key=%s" % > (location, output, key) > data = urllib.urlopen(request).read() > dlist = data.split(',') > if dlist[0] == '200': > return "%s" % (dlist[3]) > #return "%s, %s" % (dlist[2], dlist[3]) > else: > return '' > > class Business(models.Model): > physicaladdr_street1 = models.CharField("Street 1", max_length=25) > modified_date = models.DateTimeField() > latitude = models.DecimalField(max_digits=11, decimal_places=6, > null=True, blank=True) > longitude = models.DecimalField(max_digits=11, decimal_places=6, > null=True, blank=True) > > > > def save(self, force_insert=False, force_update=False): > self.modified_date = datetime.datetime.now() > self.latitude = fnclatitude() > # here I need to automatically add latitude and longitude of the > physical address. > # for exp if, fnclatitude('Chennai') returns latitude and > longitude of chenai. > super(Business, self).save(force_insert, force_update) > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---