Skip to content

Instantly share code, notes, and snippets.

@tagrudev
Created September 10, 2013 11:45
Show Gist options
  • Save tagrudev/6508262 to your computer and use it in GitHub Desktop.
Save tagrudev/6508262 to your computer and use it in GitHub Desktop.
public class MapActivity extends SherlockActivity {
private LocationManager locationManager;
Location location;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
if (item.getItemId() == R.id.currentLocationPin) {
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
CurrentLocationListener listener = new CurrentLocationListener();
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
String best = locationManager.getBestProvider(crit, false);
locationManager.requestLocationUpdates(best,1000, 10,listener);
if (location != null) {
Log.i("location", String.valueOf(location.getLatitude()));
} else {
Toast.makeText(getApplicationContext(),
"Waiting for location...", Toast.LENGTH_SHORT)
.show();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment