2013-06-04 4 views
7

Im는 KIVY, pyjnius 및 python-android에서 새로 추가되었습니다. GPS 좌표를 보여주는 Android 용 간단한 앱을 만들어야합니다. 하지만, 제가 말했듯이 저는 키비와 피포 런드 로이드에서 새로운 사람입니다. 누군가가 간단한 kivy-label-widget에서 나의 좌표를 보여주는 예를 보여 주거나 줄 수 있습니까? 감사합니다.kivy, pyjnius를 사용하여 안드로이드 용 GPS-app를 만드는 방법은 무엇입니까?

나는 이런 식으로 뭔가를하려고 노력했습니다

하지만 ... 파이썬에서

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

} 

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

답변

11
내가 한

동안 Kivy/pyjnius 내에서 GPS를 액세스 전에 데모 :

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

소스 코드를 보면 모든 것이 들어 있습니다.

+0

흥미 롭습니다. 나는 그것에 관해 볼 것이다! 현재 Kivy에서 안드로이드 통합의 깊이가 궁금합니다. – swdev

관련 문제