python mysql 调用高德geo转换经纬度为详细地址
import requests
import pandas as pd
import time
import sys
import pymysql
//python 连接数据库
db = pymysql.Connect(
host=’******’,
port=3306,
user=’******’,
passwd=’******’,
db=’******’,
charset=‘utf8’
)
//高德经纬度转详细地址API
def geocode(location):
parameters = {‘location’: location, ‘key’: ‘******’}
base = ‘http://restapi.amap.com/v3/geocode/regeo’
response = requests.get(base, parameters)
answer = response.json()
return answer[‘regeocode’][‘formatted_address’]
cursor = db.cursor()
cursor.execute(“select ccid,c_bikelong,c_bikelat from ****** where status=0 and ( (c_bikeno is not NULL) or ((c_bikelong is not NULL) and (c_bikelat is not NULL)))”)
results = cursor.fetchall()
for row in results:
print(row)
if row[1] is None:
print(“null”)
continue
if row[1] == 0.0 :
print(“0.0”)
continue
if row[1] == ‘0.0’ :
print(“0.0”)
continue
print(“row1:”+row[1])
print(“row2:”+row[2])
datas = geocode(row[1]+’,’+row[2])
print(“datas”)
print(datas)
if datas is None:
continue
if row[0] is None:
continue
sql = “update ****** set addr=’”+datas+"’,status=1 where ccid = ‘"+row[0]+"’"
print(sql)
try:
cursor.execute(sql)
db.commit()
except Exception as e:
db.rollback()
#db.close()
print(“Error:”+e.message)
db.close()
print(“ok:ok”)
---------------------
作者:arpu5211
来源:CSDN
原文:https://blog.csdn.net/weixin_40919376/article/details/94433083
版权声明:本文为博主原创文章,转载请附上博文链接!