Python try语句使用谷歌地图1.0.2
我使用的是python模块googlemaps 1.0.2,不能在用户输入未知地址的实例中使用try语句 我收到的错误消息如下所示:Python try语句使用谷歌地图1.0.2,python,google-maps,Python,Google Maps,我使用的是python模块googlemaps 1.0.2,不能在用户输入未知地址的实例中使用try语句 我收到的错误消息如下所示: GoogleMapsError: Error 602: G_GEO_UNKNOWN_ADDRESS 我的方法如下所示(没有API密钥): 我试过: except GoogleMapsError: except 'GoogleMapsError: Error 602: G_GEO_UNKNOWN_ADDRESS' 谢谢您可能尚未导入googlemaps.Goog
GoogleMapsError: Error 602: G_GEO_UNKNOWN_ADDRESS
我的方法如下所示(没有API密钥):
我试过:
except GoogleMapsError:
except 'GoogleMapsError: Error 602: G_GEO_UNKNOWN_ADDRESS'
谢谢您可能尚未导入googlemaps.GoogleMapsError异常
from googlemaps import GoogleMaps, GoogleMapsError
def get_distance(address, destination):
try:
gmaps = GoogleMaps(api_key)
directions = gmaps.directions(address,destination)
distance = directions['Directions']['Distance']['meters']/1600.0
return distance
except GoogleMapsError:
pass
从googlemaps导入googlemaps,GoogleMapsError
???
from googlemaps import GoogleMaps, GoogleMapsError
def get_distance(address, destination):
try:
gmaps = GoogleMaps(api_key)
directions = gmaps.directions(address,destination)
distance = directions['Directions']['Distance']['meters']/1600.0
return distance
except GoogleMapsError:
pass