The code Adam posted will work fine, but if you are doing other geo
stuff you could also think about using 'geopy'[1] to make the calls to
Google. That way you get proper exception handling and can move the
calls out of your class, plus if you need to calculate distances or
perform an number of other operations in different parts of your code,
you can.

[1] http://exogen.case.edu/projects/geopy/

On Nov 17, 8:19 pm, "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
-~----------~----~----~----~------~----~------~--~---

Reply via email to