Search in sources :

Example 21 with Address

use of android.location.Address in project robolectric by robolectric.

the class ShadowGeocoder method getFromLocation.

@Implementation
public List<Address> getFromLocation(double latitude, double longitude, int maxResults) throws IOException {
    wasCalled = true;
    this.lastLatitude = latitude;
    this.lastLongitude = longitude;
    if (shouldSimulateGeocodeException) {
        throw new IOException("Simulated geocode exception");
    }
    Address address = makeAddress();
    address.setAddressLine(0, addressLine1);
    address.setLocality(city);
    address.setAdminArea(state);
    address.setPostalCode(zip);
    address.setCountryCode(countryCode);
    return Arrays.asList(address);
}
Also used : Address(android.location.Address) IOException(java.io.IOException) Implementation(org.robolectric.annotation.Implementation)

Example 22 with Address

use of android.location.Address in project robolectric by robolectric.

the class ShadowGeocoderTest method setsUpHasLocationInAddressFromLocationName.

@Test
public void setsUpHasLocationInAddressFromLocationName() throws Exception {
    shadowOf(geocoder).setSimulatedHasLatLong(true, true);
    Address address = geocoder.getFromLocationName("731 Market St, San Francisco, CA 94103", 1).get(0);
    assertTrue(address.hasLatitude());
    assertTrue(address.hasLongitude());
    shadowOf(geocoder).setSimulatedHasLatLong(false, false);
    address = geocoder.getFromLocationName("731 Market St, San Francisco, CA 94103", 1).get(0);
    assertFalse(address.hasLatitude());
    assertFalse(address.hasLongitude());
}
Also used : Address(android.location.Address) Test(org.junit.Test)

Example 23 with Address

use of android.location.Address in project platform_frameworks_base by android.

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 24 with Address

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

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 25 with Address

use of android.location.Address in project YourAppIdea by Michenux.

the class AroundMeFragment method onLocationChanged.

@Override
public void onLocationChanged(Location location) {
    if (BuildConfig.DEBUG) {
        Log.d(YourApplication.LOG_TAG, "AroundmeFragment.onLocationChanged() - new loc: " + location);
    }
    this.mCurrentLocation = location;
    try {
        if (ConnectivityUtils.isConnected(this.getActivity())) {
            List<Address> addresses = mGeocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
            if (addresses != null && !addresses.isEmpty()) {
                Address address = addresses.get(0);
                this.updateCityView(address.getLocality(), address.getCountryName());
            }
        } else {
            this.updateCityView("Lat:" + location.getLatitude(), " Long: " + location.getLongitude());
        }
        this.mPlaceProvider.onLocationChanged(location);
    } catch (Exception e) {
        Log.e(YourApplication.LOG_TAG, "AroundmeFragment.onLocationChanged()", e);
    }
}
Also used : Address(android.location.Address)

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