List of usage examples for android.location Geocoder isPresent
public static boolean isPresent()
From source file:whyq.utils.location.LocationActivity.java
/** * Invoked by the "Get Address" button. * Get the address of the current location, using reverse geocoding. This only works if * a geocoding service is available.// w ww . j ava2s.c o m * * @param v The view object associated with this method, in this case a Button. */ // For Eclipse with ADT, suppress warnings about Geocoder.isPresent() @SuppressLint("NewApi") public void getAddress(View v) { // In Gingerbread and later, use Geocoder.isPresent() to see if a geocoder is available. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) { // No geocoder is present. Issue an error message Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show(); return; } if (servicesConnected()) { // Get the current location Location currentLocation = mLocationClient.getLastLocation(); // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new LocationActivity.GetAddressTask(this)).execute(currentLocation); } }
From source file:kuzki.net.exercisetracker.MainActivity.java
/** * Invoked by the "Get Address" button./* ww w . ja v a 2s .c o m*/ * Get the address of the current location, using reverse geocoding. This only works if * a geocoding service is available. * * @param v The view object associated with this method, in this case a Button. */ // For Eclipse with ADT, suppress warnings about Geocoder.isPresent() @SuppressLint("NewApi") public void getAddress(View v) { // In Gingerbread and later, use Geocoder.isPresent() to see if a geocoder is available. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) { // No geocoder is present. Issue an error message Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show(); return; } if (servicesConnected()) { // Get the current location Location currentLocation = mLocationClient.getLastLocation(); } }
From source file:com.gmail.srivi.sundaram.locgenie.MainActivity.java
/** * Invoked by the "Get Address" button. Get the address of the current * location, using reverse geocoding. This only works if a geocoding service * is available./*from w ww.j a v a 2 s . c o m*/ * * @param v * The view object associated with this method, in this case a * Button. */ // For Eclipse with ADT, suppress warnings about Geocoder.isPresent() @SuppressLint("NewApi") public void getAddress(View v) { // In Gingerbread and later, use Geocoder.isPresent() to see if a // geocoder is available. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) { // No geocoder is present. Issue an error message Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show(); return; } if (servicesConnected()) { // Get the current location Location currentLocation = mLocationClient.getLastLocation(); // Turn the indefinite activity indicator on // mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new MainActivity.GetAddressTask(this)).execute(currentLocation); } }
From source file:com.example.findmygf.MapActivity.java
public void getMyAddress(Location currentLocation) { // In Gingerbread and later, use Geocoder.isPresent() to see if a geocoder is available. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) { // No geocoder is present. Issue an error message Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show(); return;//from w w w . j a v a 2 s .c o m } // Start the background task (new MapActivity.GetMyAddressTask(this)).execute(currentLocation); }
From source file:com.example.findmygf.MapActivity.java
public void getPartnerAddress(Location currentLocation) { // In Gingerbread and later, use Geocoder.isPresent() to see if a geocoder is available. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) { // No geocoder is present. Issue an error message Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show(); return;/* w w w. j a v a 2 s. c o m*/ } // Start the background task (new MapActivity.GetPartnerAddressTask(this)).execute(currentLocation); }
From source file:com.example.shoe.DirectionsTest.java
/** * Invoked by the "Get Address" button.//from w w w . ja v a 2s . c o m * Get the address of the current location, using reverse geocoding. This only works if * a geocoding service is available. * * @param v The view object associated with this method, in this case a Button. */ // For Eclipse with ADT, suppress warnings about Geocoder.isPresent() @SuppressLint("NewApi") public void getAddress(View v) { //getLocation(); // In Gingerbread and later, use Geocoder.isPresent() to see if a geocoder is available. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) { // No geocoder is present. Issue an error message Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show(); return; } if (servicesConnected()) { // Get the current location Location currentLocation = mLocationClient.getLastLocation(); // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new DirectionsTest.GetAddressTask(this)).execute(currentLocation); } }
From source file:com.barkside.travellocblog.LocationUpdates.java
/** * Get the address of the current location, using reverse geocoding. This only works if * a geocoding service is available./* ww w. ja va2 s. co m*/ * NOT USED YET * */ // For Eclipse with ADT, suppress warnings about Geocoder.isPresent() @SuppressLint("NewApi") public void getAddress() { // In Gingerbread and later, use Geocoder.isPresent() to see if a geocoder is available. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) { // No geocoder is present. Issue an error message Toast.makeText(this, getString(R.string.no_geocoder_available), Toast.LENGTH_LONG).show(); return; } if (Utils.playServicesAvailable(this) && mLocationClient != null) { // Get the current location Location currentLocation = mLocationClient.getLastLocation(); // Turn the indefinite activity indicator on if (mActivityIndicator != null) { mActivityIndicator.setVisibility(View.VISIBLE); } // Start the background task (new LocationUpdates.GetAddressTask(this)).execute(currentLocation); } }
From source file:com.anton.gavel.GavelMain.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @Override//from w w w . j ava2 s . c o m public void onClick(View arg0) { //click listener for location button LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); //String provider = locationManager.getBestProvider(criteria, true); locationManager.requestSingleUpdate(criteria, new LocationListener() { @Override public void onLocationChanged(Location location) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) createDialog(DIALOG_NO_GEOCODING); else if (Geocoder.isPresent()) (new ReverseGeocodingTask(getBaseContext())).execute(new Location[] { location }); // Invoking reverse geocoding in an AsyncTask. } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }, null); }
From source file:com.example.transfer.MainActivity.java
/** * Invoked by the "Get Address" button. Get the address of the current * location, using reverse geocoding. This only works if a geocoding service * is available.//from www. j a v a2 s . c om * * @param v * The view object associated with this method, in this case a * Button. */ // For Eclipse with ADT, suppress warnings about Geocoder.isPresent() @SuppressLint("NewApi") public void getAddress(View v) { // In Gingerbread and later, use Geocoder.isPresent() to see if a // geocoder is available. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) { // No geocoder is present. Issue an error message Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show(); return; } if (servicesConnected()) { // Get the current location Location currentLocation = mLocationClient.getLastLocation(); // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new MainActivity.GetAddressTask(this)).execute(currentLocation); } }
From source file:com.example.android.recyclingbanks.MainActivity.java
/** * Runs when a GoogleApiClient object successfully connects. (for obtaining user gps *///from www. j a v a2 s.c om @Override public void onConnected(@Nullable Bundle bundle) { Log.i("onConnected", "connected to apiClient"); // TODO fix asking for permissions here. // Provides a simple way of getting a device's location and is well suited for // applications that do not require a fine-grained location and that do not need location // updates. Gets the best and most recent location currently available, which may be null // in rare cases when a location is not available. //TODO need to check if I activate usesGPS in settings, that when returning it will use GPS, // TODO or whether this isn't called on Activity resume. Boolean usesGPS = mSharedPrefs.getBoolean("usesGPS", false); Log.wtf("onConnected", "contain usesGPS key? " + String.valueOf(mSharedPrefs.contains("usesGPS"))); Log.wtf("onConnected", "all prefs: " + String.valueOf(mSharedPrefs.getAll())); //check if using user defined home location, or gps if (usesGPS == false) { Log.wtf("onConnected", "using gps? " + String.valueOf(usesGPS)); // TODO need to make sure this happens! Doesn't just goto EDINBURGH return; } Log.i("onConnected", "using GPS, seeking address"); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (mLastLocation != null) { mUserLatitude = mLastLocation.getLatitude(); mUserLongitude = mLastLocation.getLongitude(); mUserLatLng = new LatLng(mUserLatitude, mUserLongitude); Log.i("onConnected", "got gps, now fetching String of street"); // Determine whether a Geocoder is available to get the address from mLastLocation. if (Geocoder.isPresent()) { fetchAddress(); } else { Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_SHORT).show(); } } else { Log.wtf("onConnected", "lastLocation = null, huh?"); // no gps, skip to address screen for user to enter their address Toast.makeText(this, "no location detected\nenter mannually", Toast.LENGTH_SHORT).show(); // gps unavailable, change setting to not try for it preferences.edit().putBoolean("usesGPS", false); Intent settingsIntent = new Intent(this, SettingsActivity.class); // pass the geocoded home address through, for display as summary settingsIntent.putExtra("userAddress", mAddressOutput); startActivity(settingsIntent); //mUserLatLng = EDINBURGH; // co-ords of Edinburgh city center } // need to get data for the map Log.i("onConnected", "got gps, now getting markers with loader"); getDataLoaderGoing(); // TODO is this needed here? Is it being repeated elsewhere? mUserLatLng = new LatLng(mUserLatitude, mUserLongitude); cameraPosition = new CameraPosition.Builder().target(mUserLatLng).zoom(14).bearing(0).tilt(0).build(); Log.wtf("onConnected", "cameraPos: " + String.valueOf(cameraPosition)); m_map.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); makeHomeMarker(mUserLatLng); }