91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2023-12-25
  • 語言: Python
  • 標簽: Python??GoogleMap??API??

資源簡介

Python,通過Googlemap API獲取地點信息,輸入地點位置,輸出該地點位置詳細信息,包括經緯度等。

資源截圖

代碼片段和文件信息

#?-*-?coding:?cp936?-*-
#?Filename:get?Location?from?googleMap?
#?Input:address
#?Output:lat?&?lng
#?function:
import?urllib2
import?json

class?GoogleMap(object):
????def?__init__(self?location?postal):
????????#將地點以及郵政編碼傳入,如果沒有郵政編碼?則傳入-1
????????self.address?=?location???????????#地址
????????#組合成的googleapi地址?獲取json數據
????????self.url?=?‘http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false‘%self.address
????????print?self.url
????????self.postalcode?=?postal??????????#郵編
????????self.lat?=?0.0????????????????????#緯度
????????self.lng?=?0.0????????????????????#經度
????????
????def?getPage(self):
????????#得到頁面獲取數據
????????self.url=self.url.encode(‘utf-8‘)
????????self.url=urllib2.unquote(self.url)
????????response?=?urllib2.urlopen(self.url)
????????jsonGeocode?=?response.read()
????????jsonVal?=?json.loads(jsonGeocode)

????????HaveResult?=?False???????????????#標志變量
????????#判斷是否獲取成功
????????if(jsonVal[‘status‘]?!=?‘OK‘):
????????????return?False
????????else:
????????????for?result?in?jsonVal[‘results‘]:
????????????????#print?result[‘address_components‘]
????????????????for?val?in?result[‘address_components‘]:
????????????????????if(val[‘types‘][0]?==?‘postal_code‘):
????????????????????????#得到郵政編碼?進行比對矯正
????????????????????????if(self.postalcode?!=?“-1“?and?val[‘long_name‘]?!=?self.postalcode):
????????????????????????????continue
????????????????????????print?“postal?code:“?+?str(val[‘long_name‘])
????????????????self.lat?=?result[‘geometry‘][‘location‘][‘lat‘]
????????????????self.lng?=?result[‘geometry‘][‘location‘][‘lng‘]
????????????????print?“address:“?+?result[‘formatted_address‘].encode(‘utf-8‘)
????????????????print?“lat:“?+?str(self.lat)
????????????????print?“lng:“?+?str(self.lng)
????????????????print?“\n“
????????????????

????????????return?True
????????
def?main():
?
????address=?“北京天安門“
????newMap?=?GoogleMap(address.decode(“gbk“)?“-1“)
????newMap.getPage()

main()

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????????37??2017-11-05?13:52??說明.txt
?????文件????????2073??2017-11-05?13:47??googleMap.py

評論

共有 條評論