python bash
In some cases, you may not have a GPS module available but will still want to find out your current location. We are able to do this using the Born Again SHell command curl
在某些情况下,您可能没有可用的GPS模块,但仍想找出您的当前位置。 我们可以使用Born Again SHell命令curl来做到这一点。
命令 (The command)
The command you are interested in is:
您感兴趣的命令是:
curl ipinfo.io
This produces an output like so:
这将产生如下输出:
"ip": "90.221.xx.xx","hostname": "xxxxxxxx.bb.xxx.com","city": "London","region": "England","country": "GB","loc": "51.3xxx,-0.1xxx","org": "AS5607 Sky UK Limited","postal": "EC1A","timezone": "Europe/London","readme": "https://ipinfo.io/missingauth"
Although this is not exactly correct, It gives a rough approximation of the location-based on internet routing — pretty neat considering we don't have a GPS locator on us.
尽管这并不完全正确,但是它可以粗略地近似基于Internet路由的位置-考虑到我们没有GPS定位器,这非常简洁。
仅选择位置 (Only selecting the location)
If we only want the latitude and longitude of our location we can append loc to the previous command:
如果只想知道位置的纬度和经度,可以将loc附加到上一个命令:
curl ipinfo.io/loc
This gives just LAT, LON
as the output.
这仅给出了LAT, LON
作为输出。
从Python使用WiFi获取位置 (Getting location using WiFi from Python)
To do this we can run a shell command from python and read the returned values as so:
为此,我们可以从python运行shell命令并按以下方式读取返回值:
import os
lat,lon = os.popen('
希望您觉得这很有用,因为现在您仅可以使用Internet连接就可以找到自己。 (Hope you found this useful, as now you can find yourself using only your internet connection.)
python bash