×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    12

    Update GPS repeatedly in background

    Hi all you friendly Pythonistas,
    I'm a bit of a code newbie. So I don't know how to get my app to update the GPS location constantly in the background. Right now I use this code to update every time I press a button (which makes my app super slow):

    latitude = gps_tools.refresh()[1]
    longitude = gps_tools.refresh()[2]

    which refers to:

    def refresh():
    latitude = gps_data['position']['latitude']
    longitude = gps_data['position']['longitude']
    satellites = gps_data['satellites']['used_satellites']
    speed = gps_data['course']['speed']
    print satellites, latitude, longitude, speed, count
    return satellites, latitude, longitude, speed, count

    However, there is a part of the app that is constantly updating the GPS. This is

    def gps(event):
    print "this (gps(event)) should be called regularly"
    global gps_data
    gps_data = event

    Which is the callback for

    positioning.position(course=1,satellites=1,callback=gps, interval=200000,partial=0)

    So GPS data is being updated regularly. I just need a way to get my variables latitude and longitude to automatically update every 10 seconds or so. How do I do that asynchronously (without causing the whole app to wait for updates)?

    Thanks a lot!!!

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Update GPS repeatedly in background

    hello Neo

    what i will suggest you is to make a thread which will update your program every 10 seconds with lat/long.

    If you are not aware of thread in PyS60 feel free to ask questions here.

    Enjoy Pythoning
    Gaba88

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    12

    Re: Update GPS repeatedly in background

    Hey gaba, thanks for the suggestion. I had a look at the section on threading in the API but I'm not sure I get it.

    When I try to execute a thread in the background my Python freezes and I have to eject my memory card to exit it.

    This is the line I'm using to execute the method that I want to execute in its own background thread:

    thread.start_new_thread(background_gps_thread, ())

    This is the method I'm trying to call:

    def background_gps_check():
    # I want this to run repeatedly in the background
    #
    latitude = gps_tools.refresh()[1]
    longitude = gps_tools.refresh()[2]
    # do some stuff here

    Which in turn refers to (in gps_tools.py):

    def refresh():
    latitude = gps_data['position']['latitude']
    longitude = gps_data['position']['longitude']
    return satellites, latitude, longitude, speed, count

    which in turn refers to:

    def gps(event):
    global gps_data#, threshold
    global latitude, longitude
    gps_data = event

    which is the callback method for:

    positioning.position(course=1,satellites=1,callback=gps, interval=200000,partial=0)

    Also, how do make it so my program reacts when the position changes? Do I create a callback function?

    Thanks a lot!

Similar Threads

  1. J2me polish background image problem
    By poojs in forum Mobile Java General
    Replies: 5
    Last Post: 2009-05-29, 11:06
  2. [moved] J2me polish background image problem
    By poojs in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2009-05-25, 11:42
  3. J2me polish background image problem
    By poojs in forum Feedback - Nokia Developer Services & Infrastructure
    Replies: 1
    Last Post: 2009-05-25, 07:08
  4. Update SQL statement doesn't work
    By asheeshv in forum Symbian
    Replies: 4
    Last Post: 2008-12-11, 05:41
  5. Bluetooth GPS simulator for j2me phone
    By vgps in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-02-09, 04:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×