Example usage for android.location Geocoder isPresent

List of usage examples for android.location Geocoder isPresent

Introduction

In this page you can find the example usage for android.location Geocoder isPresent.

Prototype

public static boolean isPresent() 

Source Link

Document

Returns true if the Geocoder methods getFromLocation and getFromLocationName are implemented.

Usage

From source file:com.amansoni.tripbook.activity.LocationLookup.java

/**
 * Runs when a GoogleApiClient object successfully connects.
 *///  w  w  w .j  a v  a 2 s.co m
@Override
public void onConnected(Bundle connectionHint) {
    // Gets the best and most recent location currently available, which may be null
    // in rare cases when a location is not available.
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    if (mLastLocation != null) {
        // Determine whether a Geocoder is available.
        if (!Geocoder.isPresent()) {
            Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show();
            return;
        }
        // It is possible that the user presses the button to get the address before the
        // GoogleApiClient object successfully connects. In such a case, mAddressRequested
        // is set to true, but no attempt is made to fetch the address (see
        // fetchAddressButtonHandler()) . Instead, we start the intent service here if the
        // user has requested an address, since we now have a connection to GoogleApiClient.
        if (mAddressRequested) {
            startIntentService();
        }
    }
}

From source file:com.wspa.dm.eopiekun.GetLocationAdress.java

/**
 * Gets the address for the last known location.
 *//*from   w  w  w. j a v  a 2  s. c  o m*/
@SuppressWarnings("MissingPermission")
private void getAddress() {
    mFusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {
        @Override
        public void onSuccess(Location location) {
            if (location == null) {
                Log.w(TAG, "onSuccess:null");
                return;
            }

            mLastLocation = location;

            // Determine whether a Geocoder is available.
            if (!Geocoder.isPresent()) {
                showSnackbar(getString(R.string.no_geocoder_available));
                return;
            }

            // If the user pressed the fetch address button before we had the location,
            // this will be set to true indicating that we should kick off the intent
            // service after fetching the location.
            if (mAddressRequested) {
                startIntentService();
            }
        }
    }).addOnFailureListener(this, new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w(TAG, "getLastLocation:onFailure", e);
        }
    });
}

From source file:com.example.anish.myapplication.MainActivity.java

/**
 * Runs when a GoogleApiClient object successfully connects.
 *//*w  w w  . ja  va  2s.  co  m*/
@Override
public void onConnected(Bundle connectionHint) {

    Log.d("Location Updates", "fetch-onConnected");
    // Gets the best and most recent location currently available, which may be null
    // in rare cases when a location is not available.
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

    if (mLastLocation != null) {

        Log.d("Location Updates", "fetch-onConnected-2");
        // Dtermine whether a Geocoder is available.
        if (!Geocoder.isPresent()) {

            Log.d("Location Updates", "fetch-onConnected-3");
            Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show();
            return;
        }
        // It is possible that the user presses the button to get the address before the
        // GoogleApiClient object successfully connects. In such a case, mAddressRequested
        // is set to true, but no attempt is made to fetch the address (see
        // fetchAddressButtonHandler()) . Instead, we start the intent service here if the
        // user has requested an address, since we now have a connection to GoogleApiClient.
        if (mAddressRequested) {
            Log.d("Location Updates", "fetch-onConnected-4");
            startIntentService();
        }
    }

}

From source file:org.hansel.myAlert.LocationManagement.java

@Override
public void onLocationChanged(Location location) {
    Log.v("On Loc Change");

    if (location != null) {
        String geoCodedLocation;//from ww w  .j  a va  2  s .c o  m
        geoCodedLocation = Util.geoCodeMyLocation(location.getLatitude(), location.getLongitude(),
                getApplicationContext());

        if (isBetterLocation(location, mLocation) && Geocoder.isPresent()) {
            try {

                //enviamos al servidor el mensaje de reastreo
                Log.v("Cambio de Localizacion: " + geoCodedLocation);
            } catch (IllegalArgumentException e) {
            }
            mLocation = location;
        }
    }
}

From source file:com.kinvey.samples.citywatch.CityWatch.java

@Override
public void onLocationChanged(Location location) {
    if (Geocoder.isPresent()) {
        try {//from   ww  w  . j av a 2s  .  c o m
            nearbyAddress = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10);
            setLocationInEntity(location);

        } catch (IOException e) {
            Log.e(TAG, "OH NO!  There's a problem with the geocoder, so location is being disabled -> "
                    + e.getMessage());
            locationmanager.removeUpdates(this);

        }

    } else {
        Log.e(TAG, "OH NO!  There's a problem with the geocoder, so location is being disabled");
        locationmanager.removeUpdates(this);

    }

}

From source file:com.ternup.caddisfly.fragment.LocationFragment.java

/**
 * Invoked by the "Get Address" button./*from  www. j  av  a  2  s  .  co  m*/
 * Get the address of the current location, using reverse geo coding. This only works if
 * a geo coding service is available.
 */
public void getAddress(Location location) {

    if (NetworkUtils.checkInternetConnection(getActivity())) {

        // 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(getActivity(), R.string.no_geo_coder_available, Toast.LENGTH_LONG).show();
            return;
        }

        if (servicesConnected()) {

            // Get the current location
            //Location currentLocation = mLocationClient.getLastLocation();

            // Start the background task
            (new LocationFragment.GetAddressTask(getActivity())).execute(location);
        }
    }
}

From source file:com.google.android.gms.location.sample.locationaddress.LocationMainActivity.java

/**
 * Runs when a GoogleApiClient object successfully connects.
 *//* w  w  w  .  j a v a  2  s .co m*/
@Override
public void onConnected(Bundle connectionHint) {
    // Gets the best and most recent location currently available, which may be null
    // in rare cases when a location is not available.
    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) {
        // Determine whether a Geocoder is available.
        if (!Geocoder.isPresent()) {
            Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show();
            return;
        }
        // It is possible that the user presses the button to get the address before the
        // GoogleApiClient object successfully connects. In such a case, mAddressRequested
        // is set to true, but no attempt is made to fetch the address (see
        // fetchAddressButtonHandler()) . Instead, we start the intent service here if the
        // user has requested an address, since we now have a connection to GoogleApiClient.
        if (mAddressRequested) {
            new AsyncTask<String, Void, Classification>() {

                private Exception exception;

                protected Classification doInBackground(String... urls) {
                    Classification classification = new Classification();
                    try {
                        NaturalLanguageClassifier service = new NaturalLanguageClassifier();
                        service.setUsernameAndPassword("d1bed693-c368-4316-a7fb-ec3cc5c1deb7", "gq7WidZllcMq");
                        classification = service
                                .classify("90e7b7x198-nlc-67824", objectName + " " + description).execute();
                        System.out.println("aaaa" + classification);

                    } catch (Exception e) {
                        this.exception = e;

                    }
                    return classification;
                }

                protected void onPostExecute(Classification classification) {
                    authority = classification.getTopClass();
                    System.out.print("check" + authority);
                    startIntentService();
                }
            }.execute();

        }
    }
}

From source file:comp3111h.anytaxi.customer.RequestActivity.java

/**
 * Invoked by the "Get Address" button./*w  ww.  j  a v  a2 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() {

    // 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 RequestActivity.GetAddressTask(this)).execute(currentLocation);
    }
}

From source file:com.example.android.location.MainActivityBkp.java

/**
 * Invoked by the "Get Address" button.//  w  ww  . j  av  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 GetAddressTask(this, mActivityIndicator)).execute(currentLocation);
    }
}

From source file:com.example.android.location.MainActivity2.java

/**
 * Invoked by the "Get Address" button./*from   w w w .  j a v a2s.  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 GetAddressTask(this)).execute(currentLocation);
    }
}