Android Python获得gps状态

时间:2012-02-21 19:57:24

标签: android python gps sl4a

来自Symbian PyS60的Android Python脚本新手。我想将我的gps信息PyS60应用程序移植到Android sl4a Python。我可以得到位置,但这是关于所有。从API文档和Java示例看起来像是: 将android.location.LocationManager导入为lm satus = lm.getGpsStatus() 会做的伎俩,但我无处可去。 请帮我跟踪(cython也许???) 谢谢,Janwillem

2 个答案:

答案 0 :(得分:4)

使用GPS的python代码的简短示例:

import android, string, time
droid = android.Android()
droid.startLocating()
time.sleep(10)
l = droid.readLocation()

我在sl4a的教程页面中找到了这个 http://code.google.com/p/android-scripting/wiki/Tutorials 其中一个被称为:“跟踪你去哪里!Lua示例和python脚本来跟踪你的位置。”

完整的文档位于LocationFacade中 这里:http://www.mithril.com.au/android/doc/

答案 1 :(得分:1)

 import android, time
 droid = android.Android()
 droid.startLocating()
 time.sleep(15)
 loc = droid.readLocation().result
 if loc = {}:
   loc = getLastKnownLocation().result
 if loc != {}:
   try:
     n = loc['gps']
   except KeyError:
     n = loc['network'] 
   la = n['latitude'] 
   lo = n['longitude']
   address = droid.geocode(la, lo).result
 droid.stopLocating()