【问题标题】:How to get the postal code, providing the geographical coordinates, using geocoder in python如何在python中使用地理编码器获取邮政编码,提供地理坐标
【发布时间】:2020-06-07 00:57:43
【问题描述】:

我正在使用以下函数将邮政编码转换为地理坐标并将其附加到源数据帧(使用由 Bing maps api 提供支持的地理编码器)

我的问题是,我怎样才能修改它来做相反的事情。我想提供纬度和经度,并返回邮政编码。


def get_lats_longs(df): 

    lat_lng_coords = None
    # create lists to store our new lats and longs
    lats = []
    longs=[]
    #loop through our dataframe and look up the lat/long of each postal code
    for index, row in df.iterrows():
        postal_code=row[0]
        # loop until you get the coordinates
        lat_lng_coords = None
        while(lat_lng_coords is None):
            g = geocoder.bing('{}, Toronto, Ontario'.format(postal_code),key=bing_key)
            lat_lng_coords = g.latlng

        lats.append(lat_lng_coords[0])
        longs.append(lat_lng_coords[1])

    df['Latitude'] = lats
    df['Longitude'] = longs
    return df

提前致谢

【问题讨论】:

    标签: python bing-maps geocoder


    【解决方案1】:

    来自https://geocoder.readthedocs.io/providers/Bing.html#reverse-geocoding

    g = geocoder.google([45.15, -75.14], method='reverse')
    print(g.postal)
    

    【讨论】:

      猜你喜欢
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-26
      相关资源
      最近更新 更多