从 geopy.geocoders.google 导入 GQueryError ModuleNotFoundError:没有名为“geopy.geocoders.google”的模块

问题描述

我收到错误

ModuleNotFoundError:没有名为“geopy.geocoders.google”的模块

来自 from geopy.geocoders.google import GQueryError 上的此代码错误也是如图所示。

enter image description here

from django.db import models
from urllib.request import URLError 
from django.contrib.gis.db import models
from geopy.geocoders import GoogleV3
from django.contrib.gis import geos
from geopy.geocoders.google import GQueryError
from geopy import geocoders

# Create your models here.

class Shop(models.Model):
    name = models.CharField(max_length=100)
    location = models.PointField(u"longitude/latitude",geography=True,blank=True,null=True)
    address = models.CharField(max_length=100)
    city = models.CharField(max_length=50)

    def save(self,**kwargs):
        if not self.location:
            address = u'%s %s' % (self.city,self.address)
            address = address.encode('utf-8')
            geocoder = GoogleV3()
            try:
                _,latlon = geocoder.geocode(address)
            except (URLError,GQueryError,ValueError):
                pass
            else:
                point = "POINT(%s %s)" % (latlon[1],latlon[0])
                self.location = geos.fromstr(point)
        super(Shop,self).save()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)