how to convert from longitude and latitude to country or city?

后端 未结 5 1738
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 03:51

I need to convert longitude and latitude coordinates to either country or city, is there an example of this in python?

thanks in advance!

5条回答
  •  醉梦人生
    2021-01-31 04:37

    # Python3 program for reverse geocoding. 
    
    # importing necessary libraries 
    import reverse_geocoder as rg 
    from pandas import DataFrame
    import pandas as pd
    
    def reverseGeocode(coordinates): 
        result = rg.search(coordinates) 
        
        return result
    
        
    # Coorinates tuple.Can contain more than one pair. 
    
    if __name__ == "__main__":
        result = []
        path = "CSV_NAME.CSV"
        df = pd.read_csv(path, error_bad_lines=False)
        for i in range(0, len(df)):
            coordinates =(df["latitude"], df["longitude"]) 
            result.append(reverseGeocode(coordinates))
        print(result)
            
    

提交回复
热议问题