showing points from Python

Started by lamer, April 14, 2011, 10:59:08

0 Members and 2 Guests are viewing this topic.

lamer

I tried to supply points from python using your data structure. Unfortunaly i get Errors because the SL4A backend tries to parse the 'extra data' as JSON or to encode it to JSON.
import android
import sqlite3
import struct

def geostd(droid,lat,lon):
url='geo:%s,%s'% (lat,lon)
droid.startActivity('android.intent.action.VIEW',url)

def javautf(str1):
str2=str1.encode('utf8')
return struct.pack('>h',len(str2))+str2

def points2locus(points):
'''Takes a list of tuples
Name,HTML-desc,extradata,latitude,longitude,image
'''
return struct.pack('>i',len(points))+
''.join([struct.pack('>i',len(point[5]))+point[5]+
''.join([javautf(str3) for str3 in point[0:3]])+
struct.pack('>dd',point[3],point[4]) for point in points])

def geolocus(droid,points):
extras={'extraDataName':points2locus(points)}
droid.startActivity('android.intent.action.VIEW','menion.points:extraDataName', None,None, extras, False)

droid = android.Android()
sqlc = sqlite3.connect('/sdcard/wiglewifi/wiglewifi.sqlite')
cur=sqlc.cursor()
cur.execute('select * from network where ssid=? limit 10',('eduroam',))
result= cur.fetchall()
sqlc.close()

#geostd(droid,result[0][5],result[0][6])
geolocus([(row[1],row[0],'',row[5],row[6],'') for row in result])

 request = json.dumps(data)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 43: unexpected code byte

has anyone an idea how to create und submit such datastructure in python?
  •  

marlar

#1
Lamer, a bit offtopic but it is possible to program Android in Python?
  •  

lamer

#2
Yes it is. There is the Scripting Layer for Android (SL4A) http://code.google.com/p/android-scripting/
It might be not suitable for real apps, meant to be handed out to someone.
  •  

Menion

#3
lamer, I do not understand python language so I cannot help you directly, but if you want some update in calling to locus, let me know ...
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

lamer

#4
Hi menion,
to me it seems that this problem is not python specific. But rather a design flaw in the AndroidFacadeAPI. All the script  calls are encoded using JSON, which is meant to handle unicode data. Therefore there is no way in python to create 'invalid' utf8 to transport raw 8-bit data. To only solution I can imagine is reimplement the the whole AndroidFaceAPI call  in order to bypass the default python JSON encoding for the locus specific data structure.
  •