怎么用程序通过百度地图API批量获取具体地址的经纬度

如题所述

用程序通过百度地图API批量获取具体地址的经纬度可以选择两种方法:方法一建议使用xGeocoding工具,可以批量获得GoogleEarth/GoogleMap/百度/腾讯/高德等地图的经纬度。工具地址如下:pile(r'"x":(".+?")')pattern_y=re.compile(r'"y":(".+?")')defmercator2wgs84(mercator):#key1=mercator.keys()[0]#key2=mercator.keys()[1]point_x=mercator[0]point_y=mercator[1]x=point_x/20037508.3427892*180y=point_y/20037508.3427892*180y=180/math.pi*(2*math.atan(math.exp(y*math.pi/180))-math.pi/2)return(x,y)defget_mercator(addr):quote_addr=urllib.quote(addr.encode('utf8'))city=urllib.quote(u'齐齐哈尔市龙'.encode('utf8'))province=urllib.quote(u'黑龙江省'.encode('utf8'))ifquote_addr.startswith(city)orquote_addr.startswith(province):passelse:quote_addr=city+quote_addrs=urllib.quote(u'北京市'.encode('utf8'))api_addr="/?qt=gc&wd=%s&cn=%s&ie=utf-8&oue=1&fromproduct=jsapi&res=api&callback=BMap._rd._cbk62300"%(quote_addr,s)req=requests.get(api_addr)content=req.contentx=re.findall(pattern_x,content)y=re.findall(pattern_y,content)ifx:x=x[0]y=y[0]x=x[1:-1]y=y[1:-1]x=float(x)y=float(y)location=(x,y)else:location=()returnlocationdefrun():data=xlrd.open_workbook('Book2.xls')rtable=data.sheets()[0]nrows=rtable.nrowsvalues=rtable.col_values(0)workbook=xlwt.Workbook()wtable=workbook.add_sheet('data',cell_overwrite_ok=True)row=0forvalueinvalues:mercator=get_mercator(value)ifmercator:wgs=mercator2wgs84(mercator)else:wgs=('NotFound','NotFound')print"%s,%s,%s"%(value,wgs[0],wgs[1])wtable.write(row,0,value)wtable.write(row,1,wgs[0])wtable.write(row,2,wgs[1])row=row+1workbook.save('data.xls')if__name__=='__main__':run()
温馨提示:答案为网友推荐,仅供参考
相似回答