Search in sources :

Example 31 with Address

use of android.location.Address in project HumaneApp by Ganesh1010.

the class GPSTracker method getLocality.

/**
	 * Try to get Locality
	 * @return null or locality
	 */
public String getLocality(Context context) {
    List<Address> addresses = getGeocoderAddress(context);
    if (addresses == null) {
        Log.d(TAG, "getLocality: Address list is null");
        return null;
    } else {
        Log.d(TAG, "getLocality: Address List:" + addresses.toString());
        if (addresses.size() > 0) {
            Address address = addresses.get(0);
            Log.d(TAG, "getLocality: Address: " + address.toString());
            String locality = address.getLocality();
            return locality;
        } else {
            return null;
        }
    }
}
Also used : Address(android.location.Address)

Example 32 with Address

use of android.location.Address in project android_frameworks_base by ResurrectionRemix.

the class LocationBasedCountryDetector method getCountryFromLocation.

/**
     * @return the ISO 3166-1 two letters country code from the location
     */
protected String getCountryFromLocation(Location location) {
    String country = null;
    Geocoder geoCoder = new Geocoder(mContext);
    try {
        List<Address> addresses = geoCoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        if (addresses != null && addresses.size() > 0) {
            country = addresses.get(0).getCountryCode();
        }
    } catch (IOException e) {
        Slog.w(TAG, "Exception occurs when getting country from location");
    }
    return country;
}
Also used : Address(android.location.Address) IOException(java.io.IOException) Geocoder(android.location.Geocoder)

Example 33 with Address

use of android.location.Address in project android_frameworks_base by ResurrectionRemix.

the class GeocoderTest method testGeocoder.

public void testGeocoder() throws Exception {
    Locale locale = new Locale("en", "us");
    Geocoder g = new Geocoder(mContext, locale);
    List<Address> addresses1 = g.getFromLocation(37.435067, -122.166767, 2);
    assertNotNull(addresses1);
    assertEquals(1, addresses1.size());
    Address addr = addresses1.get(0);
    assertEquals("94305", addr.getFeatureName());
    assertEquals("Palo Alto, CA 94305", addr.getAddressLine(0));
    assertEquals("USA", addr.getAddressLine(1));
    assertEquals("94305", addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.4240385) > 0.1);
    List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
    assertNotNull(addresses2);
    assertEquals(1, addresses2.size());
    addr = addresses2.get(0);
    assertEquals("San Francisco", addr.getFeatureName());
    assertEquals("San Francisco, CA", addr.getAddressLine(0));
    assertEquals("United States", addr.getAddressLine(1));
    assertEquals("San Francisco", addr.getLocality());
    assertEquals("CA", addr.getAdminArea());
    assertEquals(null, addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.77916) > 0.1);
}
Also used : Locale(java.util.Locale) Address(android.location.Address) Geocoder(android.location.Geocoder)

Example 34 with Address

use of android.location.Address in project android_frameworks_base by crdroidandroid.

the class LocationBasedCountryDetector method getCountryFromLocation.

/**
     * @return the ISO 3166-1 two letters country code from the location
     */
protected String getCountryFromLocation(Location location) {
    String country = null;
    Geocoder geoCoder = new Geocoder(mContext);
    try {
        List<Address> addresses = geoCoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        if (addresses != null && addresses.size() > 0) {
            country = addresses.get(0).getCountryCode();
        }
    } catch (IOException e) {
        Slog.w(TAG, "Exception occurs when getting country from location");
    }
    return country;
}
Also used : Address(android.location.Address) IOException(java.io.IOException) Geocoder(android.location.Geocoder)

Aggregations

Address (android.location.Address)34 Geocoder (android.location.Geocoder)22 IOException (java.io.IOException)18 Locale (java.util.Locale)6 Location (android.location.Location)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 SuppressLint (android.annotation.SuppressLint)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 TypedArray (android.content.res.TypedArray)1 Cursor (android.database.Cursor)1 Point (android.graphics.Point)1 LocationManager (android.location.LocationManager)1 ExifInterface (android.support.media.ExifInterface)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1