Python —— Google 地圖



Python 提供了可直接將 Google 地圖中的地址轉換為地理座標的模組。這有助於查詢企業地址和定位不同地址的接近程度。

我們使用一個名為 pygeocoder 的模組來接收地址和地理編碼。此模組透過以下命令透過 pip 進行安裝。

安裝 pygeocoder

pip install pygeocoder 

查詢企業地址

我們提交一個企業名稱作為輸入,程式會給出完整的地址作為輸出。該模組使用 Google 地圖中的資料在後臺檢索結果。

from pygeocoder import Geocoder

business_name = "Workafella Business Centre - Hitec city"
print "Searching %s" %business_name
results = Geocoder.geocode(business_name)
for result in results:
    print result

當我們執行上述程式時,會得到以下輸出 −

Searching Workafella Business Centre - Hitec city
Western pearl building 1st floor, Hitech City Rd, 
Opposite HDFC Bank, Kondapur, Hyderabad, Telangana 500084, India
廣告