如何使用kivy,pyjnius为Android制作GPS应用程序?

我是KIVY,pyjnius和 pythonandroid的新手.我需要为 Android制作简单的应用程序,它显示GPS坐标.但是,正如我所说,我是kivy和pyforandroid的新手.有人可以展示/给我示例,它在简单的kivy-label-widget中显示我的坐标吗?
非常感谢!

我试过这样做但是…

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();

}

在python中

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()

解决方法

我之前做过一次在Kivy / pyjnius内访问GPS的演示:

https://github.com/tito/android-demo

看一下源代码,一切都在其中.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...