2012-03-28 7 views
-1

Ich mache eine kleine App, die die aktuellen GPS-Werte benötigt. Dafür lese ich viele Tutorials und ich habe versucht, diese sample code zu verwenden. aber ich bekomme die Werte nicht. Wenn ich den Code ausführe, wird die Anwendung zwangsweise geschlossen. Hier ist mein Logbuch.Nicht die aktuellen GPS-Werte

03-27 12:57:49.881: E/AndroidRuntime(604): FATAL EXCEPTION: main 
03-27 12:57:49.881: E/AndroidRuntime(604): java.lang.UnsatisfiedLinkError: onCreate 
03-27 12:57:49.881: E/AndroidRuntime(604): at com.google.android.maps.MapActivity.onCreate(Native Method) 
03-27 12:57:49.881: E/AndroidRuntime(604): at com.android.and.AndActivity.onCreate(AndActivity.java:48) 
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
03-27 12:57:49.881: E/AndroidRuntime(604): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-27 12:57:49.881: E/AndroidRuntime(604): at android.os.Looper.loop(Looper.java:123) 
03-27 12:57:49.881: E/AndroidRuntime(604): at android.app.ActivityThread.main(ActivityThread.java:4627) 
03-27 12:57:49.881: E/AndroidRuntime(604): at java.lang.reflect.Method.invokeNative(Native Method) 
03-27 12:57:49.881: E/AndroidRuntime(604): at java.lang.reflect.Method.invoke(Method.java:521) 
03-27 12:57:49.881: E/AndroidRuntime(604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
03-27 12:57:49.881: E/AndroidRuntime(604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
03-27 12:57:49.881: E/AndroidRuntime(604): at dalvik.system.NativeStart.main(Native Method) 

EDIT

Hier ist meine Aktivität.

public class AndActivity extends Activity implements LocationListener { 
    private TextView latituteField; 
    private TextView longitudeField; 
    private LocationManager locationManager; 
    private String provider; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     latituteField = (TextView) findViewById(R.id.TextView02); 
     longitudeField = (TextView) findViewById(R.id.TextView04); 

     // Get the location manager 
     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     // Define the criteria how to select the locatioin provider -> use 
     // default 
     Criteria criteria = new Criteria(); 
     provider = locationManager.getBestProvider(criteria, false); 
     Location location = locationManager.getLastKnownLocation(provider); 

     // Initialize the location fields 
     if (location != null) { 
      System.out.println("Provider " + provider + " has been selected."); 
      int lat = (int) (location.getLatitude()); 
      int lng = (int) (location.getLongitude()); 
      latituteField.setText(String.valueOf(lat)); 
      longitudeField.setText(String.valueOf(lng)); 
     } else { 
      latituteField.setText("Provider not available"); 
      longitudeField.setText("Provider not available"); 
     } 
    } 

    /* Request updates at startup */ 
    @Override 
    protected void onResume() { 
     super.onResume(); 
     locationManager.requestLocationUpdates(provider, 400, 1, this); 
    } 

    /* Remove the locationlistener updates when Activity is paused */ 
    @Override 
    protected void onPause() { 
     super.onPause(); 
     locationManager.removeUpdates(this); 
    } 

    @Override 
    public void onLocationChanged(Location location) { 

     int lat = (int) (location.getLatitude()); 
     int lng = (int) (location.getLongitude()); 
     latituteField.setText(String.valueOf(lat)); 
     longitudeField.setText(String.valueOf(lng)); 
    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 

    } 

    @Override 
    public void onProviderEnabled(String provider) { 
     Toast.makeText(this, "Enabled new provider " + provider, 
       Toast.LENGTH_SHORT).show(); 

    } 

    @Override 
    public void onProviderDisabled(String provider) { 
     Toast.makeText(this, "Disabled provider " + provider, 
       Toast.LENGTH_SHORT).show(); 
    } 
} 
+0

Zeigen Sie Ihr AndActivity 'onCreate (..)' Code und XML-Layout, das Sie für diese Aktivität verwenden. –

+0

@ a.ch ich habe meine AndActivity hier hinzugefügt .. – wolverine

+0

Welche Zeile ist 48th in Ihrer Aktivität? –

Antwort

0

Hallo, ich habe den Code in meinem Telefon funktioniert. Der Code funktioniert nicht in meinem Emulator. Wenn ich das auf einem Telefon installiere, funktioniert es gut. Vielen Dank für die Antworten.

1

Einige nützliche Links für eigene aktuelle GPS-Koordinaten.

http://www.firstdroid.com/2010/04/29/android-development-using-gps-to-get-current-location-2/

http://www.oudmaijer.com/2010/04/15/android-retrieving-your-current-location/

http://developer.android.com/guide/topics/location/obtaining-user-location.html

http://about-android.blogspot.in/2010/04/find-current-location-in-android-gps.html

http://www.android10.org/index.php/articleslocationmaps/209-obtaining-user-location

http://www.android10.org/index.php/articleslocationmaps/226-android-location-providers-gps-network-p

Sie können einfachere und klarere Informationen über die aktuellen GPS-Koordinaten des Benutzers finden. Einige der Tutorials sind auch da. Hoffe das wird dir helfen.

EDIT

Try this ...

public class gpsactivity { 

    private static final int gpsMinTime = 6000; 
    private static final int gpsMinDistance = 1; 

    private LocationManager locationManager = null; 
    private LocationListener locationListener = null; 
    private Location location; 
    private String bestProvider; 
    private GPSCallback gpsCallback = null; 
    private GeomagneticField geoField; 

    public gpsactivity() { 
     locationListener = new LocationListener() { 
      public void onProviderDisabled(final String provider) { 
      } 

      public void onProviderEnabled(final String provider) { 
      } 

      public void onLocationChanged(final Location location) { 
       if (location != null && gpsCallback != null) { 
//     gpsCallback.onGPSUpdate(location); 

        geoField = new GeomagneticField(
          Double.valueOf(location.getLatitude()).floatValue(), 
          Double.valueOf(location.getLongitude()).floatValue(), 
          Double.valueOf(location.getAltitude()).floatValue(), 
          System.currentTimeMillis() 
         ); 
       } 
      } 

      @Override 
      public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
       // TODO Auto-generated method stub 
      } 
     }; 
    } 

    public Location getCurrentLocation() { 

     if (locationManager != null && bestProvider != null 
       && bestProvider.length() > 0) { 
      location = locationManager.getLastKnownLocation(bestProvider); 
     } 
     return location; 
    } 

Und diese Klasse aufrufen, indem

gpsManager = new gpsactivity();    
    location = gpsManager.getCurrentLocation(); 

    if (gpsManager != null) 
      { 
       Longitude = location.getLongitude(); 
       Latitude = location.getLatitude(); 


       if (location != null) 
       { 
        location.setLatitude(Latitude); 
        location.setLongitude(Longitude);   
       } 
      } 

      intLatitude = (int) (Latitude * 1000000); 
      intLongitude = (int) (Longitude * 1000000); 

Dank ...

+0

Thak du, ich habe schon versucht, keine Codes, aber nicht die Ausgabe. bekomme o/p nur, wenn ich die Werte vom Emulator-Steuerelement sende. – wolverine

+0

verweisen meine Bearbeitung ... –

0

versuchen diese entfernen implementiert Location aus public class AndActivity erweitert Aktivität implementiert Location

und eigene Klasse erstellen wie public class MyLocationListener implementiert Location

und implementieren sie in dieser Klasse die Funktionen zum Überschreiben.

0

Hey Volworin sagte rechts ..

Emulator wir sind nicht die Curent GPS-Position erhalten .. Sie müssen und sollten Sie Ihre Anwendung auf dem Telefon installieren ..

durch die von Ihnen zuerst den GPS-Status Telefon.

folgen Sie diesem Link .. click link

Ich versuchte es bereits und testen Sie es in Android-Handy .. Seine Arbeiten.

habe einen schönen Tag.

Verwandte Themen