简体   繁体   English

在 Python 3 中使用 GPS 库

[英]Using GPS library in Python 3

I want to use GPS library in Python 3. I came across this on https://github.com/tpoche/gps-python3我想在 Python 3 中使用 GPS 库。我在https://github.com/tpoche/gps-python3上遇到了这个

How do I 'install' these files?我如何“安装”这些文件? Should I simple copy them to my folder?我应该简单地将它们复制到我的文件夹中吗? Or is there any way of installing them?或者有什么方法可以安装它们?

That project is a warts and all port of the python-gps package to Python 3.该项目是 python-gps 包到 Python 3 的所有端口。

The python-gps files live at /usr/lib/python2.7/dist-packages/gps/ python-gps 文件位于/usr/lib/python2.7/dist-packages/gps/

You can put gps-python3 files in your Python 3 path by creating and placing them in an analogous directory, eg, /usr/local/lib/python3.4/dist-packages/gps/ The module will then be available as it would in Python2.您可以通过创建gps-python3文件并将其放置在一个类似的目录中,例如/usr/local/lib/python3.4/dist-packages/gps/将它们放在 Python 3 路径中,然后该模块将可用在 Python2 中。 There is no installer没有安装程序

Another option is use gps3.py .另一种选择是使用gps3.py It's still alpha, but is a fresh python client for the gpsd.它仍然是 alpha,但它是 gpsd 的新 python 客户端。 It works with any Python from 2.7 to 3.4.它适用于从 2.7 到 3.4 的任何 Python。 It can be either placed in a directory such as /usr/local/lib/python3.4/dist-packages/gps/ , placed in the directory of your python script, or executed directly via python3 /path/to/gps3.py它既可以放在/usr/local/lib/python3.4/dist-packages/gps/等目录中,也可以放在你的python脚本目录中,也可以直接通过python3 /path/to/gps3.py执行

Your python script is easy to adapt as it uses the same name(s) as the json stream from the gpsd.您的 python 脚本很容易适应,因为它使用与 gpsd 中的 json 流相同的名称。

from gps3 import gps3
the_connection = gps3.GPSDSocket() 
the_fix = gps3.Fix()
try:
    for new_data in the_connection:
        if new_data:
            the_fix.refresh(new_data)
        if not isinstance(the_fix.TPV['lat'], str): # lat as determinate of when data is 'valid'
            speed = the_fix.TPV['speed']
            latitude = the_fix.TPV['lat']
            longitude = the_fix.TPV['lon']
            altitude  = the_fix.TPV['alt']
            # etc....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM