ActiveState Code

Recipe 576601: GPS, Python and Symbian


Retrieves your GPS co-ordinates and SMSs them to a a hard-coded or entered phone number. I did it on a Nokia E71 with an OpenSignedOnline PyS60 1.4.4 shell.

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import positioning
import messaging
import appuifw
import sys

# Get your GPS co-ordinates #
def getCoordinates():
    positioning.select_module(positioning.default_module())
    positioning.set_requestors([{'type':'service', 'format':'application','data':'position'}])
    try:
        sys.stdout.write('Retrieving GPS co-ordinates ...\n')
        data = positioning.position(course=1, satellites=1)
    except:
        sys.stdout.write('Could not retrieve GPS co-ordinates\n\n\n')
        sys.exit(-1)
    else:
        sys.stdout.write('GPS co-ordinates retrieved\n')
    return (data['position']['latitude'], data['position']['longitude'])

# Send your GPS co-ordinates as an SMS #
def sendCoordinates(coords, number):
    message = u'I\'m at location:\nLatitute  --> %f\nLongitute --> %f\n' % coords
    try:
        sys.stdout.write('Sending SMS ...\n')
        messaging.sms_send(number, message)
    except:
        sys.stdout.write('Could not send SMS :(\n\n\n')
        sys.exit(-1)
    else:
        sys.stdout.write('SMS sent :)\n')
    

if __name__ == '__main__':
    presetPhoneNumber = None # Enter phoneNumber here eg '+254722000000'
    phoneNumber = presetPhoneNumber or appuifw.query(u'Enter number: ','text')
    if not phoneNumber:
        sys.stdout.write('No number entered; exiting ...\n\n\n')
        sys.exit(-1)
    sendCoordinates(getCoordinates(), phoneNumber)

Discussion

PyS60 test drive.

Comments

  1. 1. At 9:12 a.m. on 21 apr 2009, Francisco TreviƱo said:

    Hi. I have a problem implementing this script.

    import positioning ImportError: No module named positioning

    I tried easy_install positioning

    No local packages or download links found for positioning error: Could not find suitable distribution for Requirement.parse('positioning')

    I'am using Python 2.5.2 on linux

    Thanks, the script 'looks' great! I want to see how it works.

  2. 2. At 3:04 a.m. on 29 jul 2009, Timothy Makobu (the author) said:

    Hi, you need to and S60 smartphone with GPS capabilities first, then install PyS60 on it http://sourceforge.net/projects/pys60/ You'll need to sign the pys60 shell here https://www.symbiansigned.com/app/page/public/openSignedOnline.do to unlock some modules (like positioning in my case) After all this is done, run the script from your phone.

    regards, Tim.

Sign in to comment