代码很简单,由于网上缺乏教程,在这里我做个简单分享。
1.调用gps
2.获取经纬度,以及高程等信息。
3.实用高德逆地理查询API,查询位置。
4.调用安卓系统自带语音模块,朗读位置。
# -*- coding: UTF-8 -*-
import json,requests
import androidhelper
droid = androidhelper.Android()
droid.startLocating()
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384:ECDHE:!COMPLEMENTOFDEFAULT"
Gx = ""
Gy=""
while 1:
gpsdata = droid.readLocation().result
if len(gpsdata)>0 and gpsdata['network']:
x = str(gpsdata['network']['longitude'])
y = str(gpsdata['network']["latitude"])
Gx+=x; Gy+=y
break;
droid.stopLocating()
def parse(longitude,latitude):
Msg = ''
key = '去高德注册一个api,填写自己的key值'
location = f'{longitude},{latitude}'
radius = '200'
url = f'https://restapi.amap.com/v3/geocode/regeo?output=json&location={location}&key={key}&radius={radius}&extensions=all'
res = requests.get(url)
formatted_address = res.json()['regeocode']['formatted_address']
roads = res.json()['regeocode']['roads']
print(formatted_address)
for i in roads:
Msg+=i['name']
droid.ttsSpeak("您所处的位置为:"+ Msg)
print( Gx, Gy)
parse(Gx,Gy)