为什么Google Maps api的python代码无法突然工作

尼克·陈(Nick Chen)

该代码可以以前工作,但我发现它最近无法工作。请看我的代码如下

def signal_distance(lat1,lng1,lat2,lng2):
    import simplejson, urllib
    orig_coord =lat1,lng1 
    dest_coord = lat2,lng2 
    #API request
    url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins={0}&destinations={1}&mode=transit&language=zh-TW&key=AIzaSyBlwZDhGYNTrxXiQblz20v3poJTA7zTVho".format(str(orig_coord),str(dest_coord))

    result = simplejson.load(urllib.urlopen(url))
    print result
signal_distance(25.082969,121.5549714,24.9988582,121.5788795)
瓦迪姆·格雷米亚切夫(Vadim Gremyachev)

看来,产生距离矩阵API请求signal_distance,因为它包含的功能是无效的括号originsdestinations参数。

指定的示例为我返回NOT_FOUND元素级别的状态代码:

表示该配对的起点和/或目的地无法进行地理编码

解决方案是替换来自以下位置的请求:

https://maps.googleapis.com/maps/api/distancematrix/json?origins=(<latOrig>,<lngOrig>)&destinations=(<latDest>,<lngDest>)&mode=transit&language=<lang>&key=<Key> 

https://maps.googleapis.com/maps/api/distancematrix/json?origins=<latOrig>,<lngOrig>&destinations=<latDest>,<lngDest>&mode=transit&language=<lang>&key=<Key>

修改示例

def signal_distance(lat1,lng1,lat2,lng2):
    import simplejson, urllib
    orig_coord = lat1,lng1 
    dest_coord =  lat2,lng2
    orig_coord_str = ' ,'.join(map(str, orig_coord)) 
    dest_coord_str = ' ,'.join(map(str, dest_coord)) 
    #API request
    url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins={0}&destinations={1}&mode=transit&language=zh-TW&key=AIzaSyBlwZDhGYNTrxXiQblz20v3poJTA7zTVho".format(orig_coord_str,dest_coord_str)
    result = simplejson.load(urllib.urlopen(url))
    print result

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Google Maps Places:为什么需要API密钥?

来自分类Dev

Google Maps Places:为什么需要API密钥?

来自分类Dev

为什么使用Google Maps API无法在iOS中加载Google Map?

来自分类Dev

为什么Google Maps API中未定义我的Maps对象

来自分类Dev

为什么RichMarker库中的Google Maps的zIndex无法正常工作?

来自分类Dev

为什么我的Google Maps事件监听器无法正常工作?

来自分类Dev

Google Maps API标记无法正常工作

来自分类Dev

为什么Google表格无法从Maps API中找到reverseGeocode方法?

来自分类Dev

为什么Google Maps API密钥无法识别我的引荐来源网址?

来自分类Dev

Google Maps API v3:为什么Google Maps API V3和Google Maps的搜索结果不一致?

来自分类Dev

为什么地址解析会不断返回错误的地址,但Google Maps可以正常工作

来自分类Dev

为什么我的简单Google Maps演示无法在JSFiddle上运行?

来自分类Dev

为什么Google Maps V2无法显示在模拟器中?

来自分类Dev

为什么Google Maps SDK无法在iPhone 6 iOS 8上运行?

来自分类Dev

为什么我不能使用PHP curl向Google Maps API发送太多请求?

来自分类Dev

Android Studio:为什么我在全新的Google Maps API项目上遇到了多dex错误?

来自分类Dev

为什么我的Google Maps API被嵌入但没有显示在HTML页面上?

来自分类Dev

Google Maps API v3:为什么仅在缩放时MakerWithLabel的标签才会更改?

来自分类Dev

为什么我的应用程序(使用Google Maps API 2)每次都会崩溃?

来自分类Dev

为什么不需要Google Maps API密钥来做到这一点?

来自分类Dev

为什么我不能将Google Maps getCurrentPosition与地点搜索API结合使用

来自分类Dev

为什么 Google Maps API 结果中某些位置缺少城市名称?

来自分类Dev

为什么在使用 Google Maps API 时全局设置的 JS 变量显示为未定义?

来自分类Dev

Google Maps自动完成api v3突然停止工作

来自分类Dev

版本中的Android Google Maps API无法正常工作

来自分类Dev

Google Maps API RefererNotAllowedError

来自分类Dev

Google Maps API DeletedApiProjectMapError

来自分类Dev

Google Maps Api许可

来自分类Dev

Google Maps Api

Related 相关文章

  1. 1

    Google Maps Places:为什么需要API密钥?

  2. 2

    Google Maps Places:为什么需要API密钥?

  3. 3

    为什么使用Google Maps API无法在iOS中加载Google Map?

  4. 4

    为什么Google Maps API中未定义我的Maps对象

  5. 5

    为什么RichMarker库中的Google Maps的zIndex无法正常工作?

  6. 6

    为什么我的Google Maps事件监听器无法正常工作?

  7. 7

    Google Maps API标记无法正常工作

  8. 8

    为什么Google表格无法从Maps API中找到reverseGeocode方法?

  9. 9

    为什么Google Maps API密钥无法识别我的引荐来源网址?

  10. 10

    Google Maps API v3:为什么Google Maps API V3和Google Maps的搜索结果不一致?

  11. 11

    为什么地址解析会不断返回错误的地址,但Google Maps可以正常工作

  12. 12

    为什么我的简单Google Maps演示无法在JSFiddle上运行?

  13. 13

    为什么Google Maps V2无法显示在模拟器中?

  14. 14

    为什么Google Maps SDK无法在iPhone 6 iOS 8上运行?

  15. 15

    为什么我不能使用PHP curl向Google Maps API发送太多请求?

  16. 16

    Android Studio:为什么我在全新的Google Maps API项目上遇到了多dex错误?

  17. 17

    为什么我的Google Maps API被嵌入但没有显示在HTML页面上?

  18. 18

    Google Maps API v3:为什么仅在缩放时MakerWithLabel的标签才会更改?

  19. 19

    为什么我的应用程序(使用Google Maps API 2)每次都会崩溃?

  20. 20

    为什么不需要Google Maps API密钥来做到这一点?

  21. 21

    为什么我不能将Google Maps getCurrentPosition与地点搜索API结合使用

  22. 22

    为什么 Google Maps API 结果中某些位置缺少城市名称?

  23. 23

    为什么在使用 Google Maps API 时全局设置的 JS 变量显示为未定义?

  24. 24

    Google Maps自动完成api v3突然停止工作

  25. 25

    版本中的Android Google Maps API无法正常工作

  26. 26

    Google Maps API RefererNotAllowedError

  27. 27

    Google Maps API DeletedApiProjectMapError

  28. 28

    Google Maps Api许可

  29. 29

    Google Maps Api

热门标签

归档