lenonganem
Posts: 4
Joined: Sun May 20, 2018 5:07 pm

Working with GPS to activate audios

Sun Jul 15, 2018 1:50 pm

Hy guys! First, i wanna say sorry about my english. :D

I'm write one code to my rasp+neo6m gps. I wanna get gps lat and long and compare with others points of lat and long. Is like this, when the car cross some point off lat and long one audio saying he was passed for the specified point. My code was like this:
The problem was when i cross the point with car, do not play the audio.

Code: Select all

from gps3 import agps3
import sys
import os
import pygame.mixer
import pygame, time
import json
import math

pygame.mixer.init(44100)
gps_socket = agps3.GPSDSocket()
data_stream = agps3.DataStream()
gps_socket.connect()
gps_socket.watch()
lat1 = -12.924511667
lon1 = -38.465796667
lat2 = -12.962735
lon2 = -38.46010

for new_data in gps_socket:
 if new_data:
  data_stream.unpack(new_data)              
  print("Longitude =" , data_stream.lon)
  print("Latitude =" , data_stream.lat)
 if "lat1" < "Latitude" < "lat2"" lon1"  < "Longitude" < "lon2":
  music = pygame.mixer.music
  music.load('/home/pi/Documents/beep.mp3')
  music.play()
  print('Aloalo!')
  while pygame.mixer.music.get_busy():
          time.sleep(1)

gordon77
Posts: 3370
Joined: Sun Aug 05, 2012 3:12 pm

Re: Working with GPS to activate audios

Sun Jul 15, 2018 4:05 pm

Code: Select all

   if "lat1" < "Latitude" < "lat2"" lon1"  < "Longitude" < "lon2": 
Does this need an 'and' between "lat2" and "lon1"?

Are you comparing strings and numbers?

Where do latitude and longitude gets their values set?

Why all the "" in the if statement?

How about...

if (lat1 < data_stream.lat < lat2) and (lon1 < data_stream.lon < lon2):

lenonganem
Posts: 4
Joined: Sun May 20, 2018 5:07 pm

Re: Working with GPS to activate audios

Sun Jul 15, 2018 5:06 pm

Hey,

Im realy newbie using python. :D :D

Are you comparing strings and numbers?

The first time i tried use some like this

Code: Select all

if (lat1 < data_stream.lat < lat2) and (lon1 < data_stream.lon < lon2):
i have get you cant compare string with float, because that, i tried put like float to compare.

Where do latitude and longitude gets their values set?
I get from module NEO6M GPS connect on gpio raspberry.

Why all the "" in the if statement?
Because for me, only works the program when i put between ". If i dont put i get " you cant compare string with float."

I will try this .

Code: Select all

if (lat1 < data_stream.lat < lat2) and (lon1 < data_stream.lon < lon2):

gordon77
Posts: 3370
Joined: Sun Aug 05, 2012 3:12 pm

Re: Working with GPS to activate audios

Sun Jul 15, 2018 5:37 pm

You could try...

if (lat1 < float(data_stream.lat) < lat2) and (lon1 < float(data_stream.lon) < lon2):

But you may need to see how Decimal places there are.

lenonganem
Posts: 4
Joined: Sun May 20, 2018 5:07 pm

Re: Working with GPS to activate audios

Sun Jul 15, 2018 5:48 pm

When i get lat and long i get like this.

Longitude = -38.460173333
Latitude = -12.962696667

I tryed with this

Code: Select all

for new_data in gps_socket:
 if new_data:
  data_stream.unpack(new_data)              
  print("Longitude =" , data_stream.lon)
  print("Latitude =" , data_stream.lat)
  long = type(data_stream.lon)
  if long == float :
      long = float(data_stream.lon)
      lati = float(data_stream.lat)
      if (lat1 < lati < lat2) and (lon1 < long < lon2): 
       music = pygame.mixer.music
       music.load('/home/pi/Documents/beep.mp3')
       music.play()
       print('Aloalo!')
       while pygame.mixer.music.get_busy():
           time.sleep(1)
and I tried with this

Code: Select all

  if (lat1 < data_stream.lat < lat2) and (lon1 < data_stream.lon < lon2): 
and apparently it works, when I change the points, the program goes into if

Return to “Python”

Who is online

Users browsing this forum: No registered users and 14 guests