Hello,
I used this tutorial to write my app. I use the DDMS Location Manager to change my location virtually.
Unfortunally I always get a location of 0.0 for long and lat. Even if I switch them later in the prog with locationchanged-method I get 0.0.
Code is this:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//---use the LocationManager class to obtain GPS locations---
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Location lastLoc = lm.getLastKnownLocation("gps");
curLocation = "Standort: \nLatitude: " + lastLoc.getLatitude() + "\nLongitude: " + lastLoc.getLongitude();
upperText = (TextView) findViewById(R.id.TextView01);
upperText.setText(curLocation);
}
and
@Override
public void onLocationChanged(Location loc)
{
if (loc != null) {
Toast.makeText(getBaseContext(),
"Location changed : Lat: " + loc.getLatitude() +
" Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();
}
if (loc != null)
{
upperText.setText(curLocation + "\n\nStandort: \nLatitude: " + loc.getLatitude()
+ "\nLongitude: " + loc.getLongitude());
}
}
Something's missing, but I don't know what... :/
I'd be really pleased if anyone could help =)!