通过python获取你的位置 [英] Get your location through python

查看:165
本文介绍了通过python获取你的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,我可以通过python获取我的设备的位置。目前我不得不使用硒并打开浏览器,使用位置服务网站并将结果设置为经纬度变量。



但是有没有更简单的方法来做到这一点?



更新:我在RaspberryPi上使用3G加密狗,所以寻找一种方法来获得特定的经纬度 - 我可以成功地通过web服务来做到这一点,只是想知道是否有更快的方式构建到Python的这些请求?

解决方案

假设:



正在寻找位置的设备是运行Python
的设备您可以访问Internet(自提到位置服务网站以来似乎公平)



在这种情况下,有些服务与注释中链接的服务类似,请求的IP用于生成位置。例如, http://freegeoip.net/

 导入请求
导入json

send_url ='http://freegeoip.net/json'
r = requests.get(send_url)
j = json.loads(r.text)
lat = j ['latitude']
lon = j ['longitude']
pre>

缺点



只有IP用于生成位置。


Is there anyway that I can get the location of my device through python. Currently I am having to use selenium and open up a browser, use a location service website and setting the result of that to variables for lat/long.

But is there an easier way to do this?

UPDATE: I am using a 3G dongle on my RaspberryPi, so looking for a way to get the specific lat/long of it - I can successfully do this through web service, just wondering if there is a quicker way built into python for these requests?

解决方案

Assumptions:

The device for which location is being sought is the one running the Python You have Internet access (seems fair since you mention a location service website)

In such a case, there are services similar to the one linked in the comment where the IP of the request is used to generate the location. For example, http://freegeoip.net/.

import requests
import json

send_url = 'http://freegeoip.net/json'
r = requests.get(send_url)
j = json.loads(r.text)
lat = j['latitude']
lon = j['longitude']

Drawbacks

Only IP is used to generate location.

这篇关于通过python获取你的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆