Reputation: 9373
All I'm trying to do is return the long/lat values from the last know location and if that is null then pull new coords.
I'm very new to this, This is what I have:
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
public class GPS extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
TextView output;
output = (TextView) findViewById(R.id.output);
output.append("\n\nLocations (starting with last known):");
Location location = locationManager.getLastKnownLocation(bestProvider);
printLocation(location);
}
}
Upvotes: 0
Views: 2467
Reputation: 22740
And don't forget to add ACCESS_COARSE_LOCATION
or ACCESS_FINE_LOCATION
permissions to your AndoidManifest.xml.
Upvotes: 2