List of usage examples for android.location Geocoder isPresent
public static boolean isPresent()
From source file:com.maps.locationsecond.MainLocationActivity.java
/** * Invoked by the "Get Address" button.//w w w . j av a2s . 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(); // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new MainLocationActivity.GetAddressTask(this)).execute(currentLocation); } }
From source file:com.yayandroid.utility.MapHelperFragment.java
/** * After getting myLocation, this method tries to get user's current * address. First with GeoCoder, if it cannot then it looks up googleApis to * get address online and parseS it./*w w w . j a v a2 s. co m*/ */ private void GetLocationInfo() { if (runningThreadGetLocationInfo || myLocation == null) return; new Thread(new Runnable() { @SuppressLint("NewApi") @Override public void run() { runningThreadGetLocationInfo = true; Address address = null; if (Build.VERSION_CODES.FROYO < Build.VERSION.SDK_INT) { if (Geocoder.isPresent()) { try { if (getActivity() != null) { Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(myLocation.getLatitude(), myLocation.getLongitude(), 1); if (addresses.size() > 0) { address = addresses.get(0); } } } catch (Exception ignored) { /* * After a while, GeoCoder start to throw * "Service not available" exception. really weird * since it was working before (same device, same * Android version etc..) */ } } } if (address != null) { // i.e., GeoCoder success parseAddressInformation(address); } else { // i.e., GeoCoder failed fetchInformationUsingGoogleMap(); } runningThreadGetLocationInfo = false; } }).start(); }
From source file:io.melle.carboncycle.MapsActivity.java
/** * Invoked by the "Get Address" button.//from w ww .j a v a 2 s . 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(); // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new MapsActivity.GetAddressTask(this)).execute(currentLocation); } }
From source file:com.example.Qskip.LocatorActivity.java
/** * Invoked by the "Get Address" button./*from w ww.j ava 2s .co 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(); // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new LocatorActivity.GetAddressTask(this)).execute(currentLocation); } }
From source file:name.gumartinm.weather.information.activity.MapActivity.java
/** * Getting the address of the current location, using reverse geocoding only works if * a geocoding service is available.//w ww . j a v a 2 s .c o m * */ private void getAddressAndUpdateUI(final double latitude, final double longitude) { // 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()) { this.removeButtonsFragment(); this.removeProgressFragment(); this.addProgressFragment(latitude, longitude); } else { this.removeProgressFragment(); this.addButtonsFragment(); // No geocoder is present. Issue an error message. Toast.makeText(this, this.getString(R.string.weather_map_no_geocoder_available), Toast.LENGTH_LONG) .show(); // Default values final String city = this.getString(R.string.city_not_found); final String country = this.getString(R.string.country_not_found); final WeatherLocation weatherLocation = new WeatherLocation().setLatitude(latitude) .setLongitude(longitude).setCity(city).setCountry(country); updateUI(weatherLocation); } }
From source file:com.example.android.location.MainActivity.java
/** * Invoked by the "Get Address" button.//from w ww . j a va 2 s .com * 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(); // 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.loc.MainActivity.java
/** * Invoked by the "Get Address" button.//from w w w . ja va 2 s . 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()) { if (!isOnline(this)) { Toast.makeText(this, "Internet not available", Toast.LENGTH_SHORT).show(); return; } // 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.stbam.rssnewsreader.location.LocationActivity.java
/** * Invoked by the "Get Address" button./*w ww . ja va2s.com*/ * 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(); // Turn the indefinite activity indicator on // mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new LocationActivity.GetAddressTask(this)).execute(currentLocation); } }
From source file:com.stbam.rssnewsreader.location.LocationActivity.java
@SuppressLint("NewApi") public void getAddress2(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;/*from ww w. j a v a2s. com*/ } 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.GetAddressTask2(this)).execute(currentLocation); } }
From source file:com.sorin.medisync.map.InfoMapActivity.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 . ja 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) { boolean on = ((ToggleButton) v).isChecked(); if (on) { v.animate().translationX(TX_END).translationY(TY_END); // 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; } // Get the current location Location currentLocation = mLocationClient.getLastLocation(); // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); // Start the background task (new InfoMapActivity.GetAddressTask(this)).execute(currentLocation); } else { v.animate().translationX(TX_START).translationY(TY_START); // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.INVISIBLE); // Start the background task mAddress.setText("No address updates"); } }