吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1171|回复: 15
收起左侧

[学习记录] python界面操作式调用高德api接口查找经纬度,用处不大仅供学习。

[复制链接]
Mrhe 发表于 2023-7-6 09:18
本帖最后由 Mrhe 于 2023-7-6 09:21 编辑

import tkinter as tk
import requests

def search_location(api_key, name):
    url = 'https://restapi.amap.com/v3/place/text'
    parameters = {
        'key': api_key,
        'keywords': name,
        'city': '盐城',
        'citylimit': 'true'
    }

    response = requests.get(url, params=parameters)
    data = response.json()

    if data['status'] == '1' and int(data['count']) >= 1:
        pois = data['pois']
        locations = [(poi['name'], poi['location']) for poi in pois]
        return locations
    else:
        return None

def search_and_display():
    api_key = api_key_entry.get()
    name = entry.get()
    locations = search_location(api_key, name)

    if locations:
        result_text.delete(1.0, tk.END)
        for location in locations:
            result_text.insert(tk.END, f"{location[0]}: {location[1]}\n")
    else:
        result_text.delete(1.0, tk.END)
        result_text.insert(tk.END, "未找到符合条件的地点。")

# 创建主窗口
window = tk.Tk()
window.title('地点搜索和显示')

# 创建API密钥标签和文本输入框
api_key_label = tk.Label(window, text='请输入API密钥:')
api_key_label.pack()
api_key_entry = tk.Entry(window)
api_key_entry.pack()

# 创建地点搜索标签和文本输入框
label = tk.Label(window, text='请输入要搜索的地点名称:')
label.pack()
entry = tk.Entry(window)
entry.pack()

# 创建搜索按钮
button = tk.Button(window, text='搜索并显示', command=search_and_display)
button.pack()

# 创建结果显示文本框
result_label = tk.Label(window, text='搜索结果:')
result_label.pack()
result_text = tk.Text(window, height=10, width=50)
result_text.pack()

# 进入主循环
window.mainloop()

点评

发帖支持MD格式,也支持插入代码块,为了更好的阅读,建议使用相关功能。  发表于 2023-7-6 10:22

免费评分

参与人数 3吾爱币 +1 热心值 +2 收起 理由
羽翼誓言 + 1 我很赞同!
crary06 + 1 我很赞同!
shengruqing + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| Mrhe 发表于 2023-7-6 09:24
需要直接使用的可以直接下载:
链接:https://pan.baidu.com/s/1PdLzaSTZbAGSMmlsdxDN1Q
提取码:5u47
江河宁夏 发表于 2023-7-6 09:26
知心 发表于 2023-7-6 09:27
下次发代码建议用代码组件包一下,看起来更整洁。
image.png

免费评分

参与人数 1吾爱币 +1 收起 理由
67haha + 1 学会了

查看全部评分

cwoy 发表于 2023-7-6 09:33
好厉害啊👍
wangsuqin 发表于 2023-7-6 09:38
感觉有了chatgpt这些问题都迎刃而解了
Zoeylander 发表于 2023-7-6 09:49
非常感谢,学习了!
shy20070509 发表于 2023-7-6 10:02
谢谢分享,试一下功能
jjoobb123 发表于 2023-7-6 10:19
高手,感谢分享
zy2020 发表于 2023-7-6 10:44
这个很实用,我正好想用来查看地图
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-23 15:23

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表