D
Der
Neues Mitglied
- 0
hi
ich versuche gerade eine funktionierende GPS Funktion hinzubekommen, doch die Funktion onLocationChanged wird bei mir nicht aufgerufen????
Wenn ich das GPS ein/ausschalte kommt jeweils die entsprechende Meldung, aber die aktuelle Position wird nicht angezeigt. Kann mir jemand bitte weiterhelfen??
lg
ich versuche gerade eine funktionierende GPS Funktion hinzubekommen, doch die Funktion onLocationChanged wird bei mir nicht aufgerufen????
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] GpstrackerActivity [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity
{
[/LEFT]
[/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf][LEFT]/** Called when the activity is first created. */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/LEFT]
[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464][LEFT]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onCreate(Bundle savedInstanceState)
{
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onCreate(savedInstanceState);
setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]main[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
Toast.[I]makeText[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ANFANG"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();[/LEFT]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][LEFT]/* Use the LocationManager class to obtain GPS locations */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
LocationManager mlocManager = (LocationManager)getSystemService
(Context.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LOCATION_SERVICE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
LocationListener mlocListener = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]GPS_PROVIDER[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], 0,
0, mlocListener);
Toast.[I]makeText[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"1"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
}
[/LEFT]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][LEFT]/* Class My Location Listener */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MyLocationListener [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]implements[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] LocationListener
{
[/LEFT]
[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464][LEFT]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
String Text = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"My current location is: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] +
[/LEFT]
[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][LEFT]"Latitud = "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + loc.getLatitude() +
[/LEFT]
[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][LEFT]"Longitud = "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + loc.getLongitude();
Toast.[I]makeText[/I]( getApplicationContext(),
Text,
Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
}
[/LEFT]
[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464][LEFT]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onProviderDisabled(String provider)
{
Toast.[I]makeText[/I]( getApplicationContext(),
[/LEFT]
[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][LEFT]"Gps Disabled"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ).show();
}
[/LEFT]
[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464][LEFT]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onProviderEnabled(String provider)
{
Toast.[I]makeText[/I]( getApplicationContext(),
[/LEFT]
[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][LEFT]"Gps Enabled"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
}
[/LEFT]
[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464][LEFT]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onStatusChanged(String provider, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] status, Bundle
extras)
{
Toast.[I]makeText[/I](getApplicationContext
(),[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ENDE"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
}
}[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* End of Class MyLocationListener */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/LEFT]
}[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* End of UseGps Activity */
[/COLOR][/SIZE][/COLOR][/SIZE]
Wenn ich das GPS ein/ausschalte kommt jeweils die entsprechende Meldung, aber die aktuelle Position wird nicht angezeigt. Kann mir jemand bitte weiterhelfen??
lg