mysql geocode_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

版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值