Is it possible to store GPS data using plyer.gps?

619 views
Skip to first unread message

Weixuan Jiang

unread,
Feb 25, 2022, 9:39:20 PM2/25/22
to Kivy users support
Recently I found an example that can be used to get GPS data, https://github.com/kivy/plyer/tree/master/examples/gps. But when I try to modify the code to store GPS data in real-time, there is a problem. I tried to convert the data into elements in the list and then store it, or get a string like in the example and then try to get it, but I can't succeed every time.

I think maybe it's because I don't know much about how plyer.gps works, maybe someone can give me some hints?

Thank you so much!


Message has been deleted

Weixuan Jiang

unread,
Feb 27, 2022, 4:51:22 PM2/27/22
to Kivy users support
Hello,

I feel like my question might not be clear enough.

I found out that with the codes in the example the GPS data can be obtained and displayed on the screen.
But I don't know how to extract GPS data such as latitude and longitude and speed. Then store these values in a local file, or insert values into a database table.

Could you please give me some hints?

Robert

unread,
Feb 27, 2022, 6:40:03 PM2/27/22
to Kivy users support
Still not nearly clear enough, it is better to ask a very specific question. "I don't know" doesn't tell anybody what you need to know (unless you are hoping somebody will do it for you)

> But I don't know how to extract GPS data such as latitude and longitude and speed.

You don't say what platform you are using, but if you don't understand the fields look at the plyer code for that platform, that will use the platfrom api, and the platform documentation will (hopefully) explain the fields in detail.

> Then store these values in a local file, or insert values into a database table.

Saving to a file is Python programming, common formats to save as are csv, json, and sqlite. Any good Python tutorial will help.

Weixuan Jiang

unread,
Feb 28, 2022, 8:38:05 AM2/28/22
to Kivy users support
Hello,

Sorry, my question is not clear enough.


.kv file
```
Label:

text: app.gps_location

```

main.py
```
gps_location = StringProperty()


@mainthread


def on_location(self, **kwargs):


self.gps_location = '\n'.join([


'{}={}'.format(k, v) for k, v in kwargs.items()])
 

 

gps.configure(on_location=self.on_location,


on_status=self.on_status)

gps.start()  
gps.stop()
```

These codes make GPS data can be shown on the screen when pressing the start.

But when I try to do something like this:

```
                   latitude, longitude, speed, bearing, altitude, accuracy =\
                     self.gps_location.split("=")[1], self.gps_location.split("=")[3], \
                     self.gps_location.split("=")[5], self.gps_location.split("=")[7], self.gps_location.split("=")[9], \
                     self.gps_location.split("=")[12]
```

or something like this:

```
@mainthread
def on_location(self, **kwargs):

return kwargs.get('lat'), kwargs.get('lon'), kwargs.get('speed'), kwargs.get('bearing'),  kwargs.get('altitude'), kwargs.get('accuracy')

latitude, longitude, speed, bearing, altitude, accuracy = self.on_location
```

It can not work. The values are always can not be gotten. I wonder the cause of this? Is it because the value keeps changing or what?

Thanks so much!

Robert

unread,
Feb 28, 2022, 5:41:57 PM2/28/22
to Kivy users support
There seems to be a 'return' in on_location().
The app code does not call on location so it can't return anything, it is called by a change in gps data.

Go step by step.
To get started,  inside on_location() save self.gps_location to a file. Later see all the changes in the file.
Once you see things working, save the individual values in some format you like.

Youxiu

unread,
Mar 1, 2022, 9:49:49 AM3/1/22
to Kivy users support
Thanks, that's helpful.
Reply all
Reply to author
Forward
0 new messages