Python中文
首页
教程
问答
标签
搜索
登录
注册
如何使用kivy,pyjnius为android开发GPS应用程序?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我是KIVY,pyjnius和PythonAndroid的新手。我需要为android制作一个简单的应用程序,显示GPS坐标。但是,就像我说的,我是新来的基维和小圆孔虫。有人能给我举个例子,在简单的kivy标签小部件中显示我的坐标吗? 谢谢!</p> <p>我试过这样做,但是。。。</p> <pre><code> package org.renpy.android; //import java.util.ArrayList; //import java.util.List; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.content.Context; import android.os.Bundle; import android.os.Looper; import java.lang.Thread; import android.app.Activity; public class KivyGps { LocationManager lm; Thread gpsThread; public long minDistance = 1; public int minTime = 1000; static class KivyLocationListener implements LocationListener { public Location lastLocation = new Location("Other"); //private List<LocationListener> listeners = new ArrayList<LocationListener>(); public void onLocationChanged(Location location) { // TODO Auto-generated method stub lastLocation = location; //updateListeners(location); } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } // TODO Auto-generated method stub return lastLocation; } } static public KivyLocationListener locationListener = new KivyLocationListener(); public Thread init(final Activity currActivity) { gpsThread = new Thread( new Runnable() { public void run() { try { Looper.prepare(); lm = (LocationManager) currActivity.getSystemService( Context.LOCATION_SERVICE ); lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, minTime, minDistance, locationListener ); Looper.loop(); } catch ( Exception e ) { e.printStackTrace(); } } } ); return gpsThread; } //gpsThread.start(); } </code></pre> <p>在python中</p> <pre><code>from jnius import autoclass LocationListener = autoclass('android.location.LocationListener') LocationManager = autoclass('android.location.LocationManager') LocationProvider = autoclass('android.location.LocationProvider') Location = autoclass('android.location.Location') Looper = autoclass('android.os.Looper') Context = autoclass('android.content.Context') KivyGps = autoclass('org.renpy.android.KivyGps') currentActivity = cast('android.app.Activity', PythonActivity.mActivity) lm = currentActivity.getSystemService( Context.LOCATION_SERVICE) if lm.isProviderEnabled( LocationManager.GPS_PROVIDER ): print 'CON GPS' else: print 'SIN GPS' lps = lm.getAllProviders() for lp in lps.toArray(): print lp #Arreglar problema de derechos ACCESS_FINE_LOCATION en Kivy Launcher lp = lm.getProvider('gps') ll = KivyGps.locationListener kgps = KivyGps() gpsThread = kgps.init( currentActivity ) gpsThread.start() loc = ll.getCurrentLocation() if loc: print loc.getLatitude() print loc.getLongitude() </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我刚才在Kivy/pyjnius中做了一个访问GPS的演示:</p> <p><a href="https://github.com/tito/android-demo" rel="nofollow noreferrer">https://github.com/tito/android-demo</a></p> <p>看看源代码,一切都在里面。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何找到类似于How'matplotlib.pyplot.gcf()`works?
1 回答
如何找到类字段的定义?
1 回答
如何找到精灵在团队中的位置?
4 回答
如何找到素数,但有错误。我找不到你
4 回答
如何找到素数(Python)
10 回答
如何找到索引i右侧的不同值
1 回答
如何找到索引Numpy数组时将折叠哪些轴?
6 回答
如何找到索引中的值,在列表中增加值?
7 回答
如何找到纬度/经度/高度点之间的三维距离?
3 回答
如何找到线和numpy meshgrid生成的曲面之间的交点?
4 回答
如何找到线段上距任意点最近的点?
2 回答
如何找到组中所有可能的子组
3 回答
如何找到组内值之间的最小差异
2 回答
如何找到经过训练的朴素贝叶斯分类器用于决策的单词?
5 回答
如何找到给selenium webdriver对象的文件夹名?
4 回答
如何找到给出最佳分数的列车测试分割的最佳随机状态值?
7 回答
如何找到给定Python发行版提供的模块?
2 回答
如何找到给定subversion工作副本的根文件夹
8 回答
如何找到给定一维阵列中的所有峰值?
2 回答
如何找到给定列表中的字符串组合,这些字符串加起来就是某个字符串(没有外部库)
2 回答