如何使用python flask使用GPS获取当前位置?

2024-06-08 17:01:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用Python Flask开发的项目,它可以使用Google地图找到附近所有的服装店。
到目前为止,我可以用我的代码做到这一点,但是我现在的位置是从我的IP地址得到的,这个IP地址来自互联网服务提供商,所以。。我不想要。。因为互联网服务提供商不太靠近我的位置,我想要更准确的位置,可以得到当前用户的GPS。。
但到目前为止。。我不需要使用python flask获得教程或源代码。。
所以我的问题。。烧瓶能做到吗。。?,如果没有,其他人有什么解决办法。。?在

以下是我获取当前ISP位置并查找附近所有位置的代码:

import googlemaps
import geocoder
from googleplaces import GooglePlaces, types

# you can get the API KEY here:
# https://developers.google.com/console
API_KEY = 'MY_API_KEY'

gmaps = googlemaps.Client(key=API_KEY)
locations = gmaps.geolocate()

latitude = locations['location']['lat']
longitude = locations['location']['lng']

g = geocoder.google([latitude, longitude], method='reverse')

get_json_values = g.json

my_current_position = get_json_values['address']

google_places = GooglePlaces(API_KEY)

query_result = google_places.nearby_search(
    location=my_current_position,
    keyword='baju', radius=3200)

for place in query_result.places:
    print(place.name)
    place.get_details()
    print(place.url)

Tags: key代码importapijsongetgoogleplace