Example usage for android.location Address getAddressLine

List of usage examples for android.location Address getAddressLine

Introduction

In this page you can find the example usage for android.location Address getAddressLine.

Prototype

public String getAddressLine(int index) 

Source Link

Document

Returns a line of the address numbered by the given index (starting at 0), or null if no such line is present.

Usage

From source file:Main.java

public static String getNameFromLocation(final double lat, final double lng, final Context context)
        throws IOException {
    final Geocoder gc = new Geocoder(context, Locale.getDefault());
    if (Geocoder.isPresent()) {
        final List<Address> list = gc.getFromLocation(lat, lng, 1);

        if (list.size() > 0) {
            final Address address = list.get(0);
            return address.getAddressLine(0);
        }//  w ww  .  ja v  a  2 s.  co m
    }
    return "Fehler, bitte manuell eintragen";
}

From source file:Main.java

public static String extractAddressLines(Address address) {
    String resultAddress = null;/* w  w  w  .j  a  v a 2  s  .  c om*/
    for (int i = 0, tam = address.getMaxAddressLineIndex(); i < tam; i++) {
        resultAddress += address.getAddressLine(i);
        resultAddress += i < tam - 1 ? ", " : "";
    }

    return resultAddress;
}

From source file:Main.java

public static @Nullable String getAddressStringOneLine(@Nullable final Address address) {

    if (address == null) {
        return null;
    }/*from   w  ww  . j a v a 2  s  .c om*/

    final StringBuilder sb = new StringBuilder(address.getAddressLine(0));
    if (address.getMaxAddressLineIndex() >= 1) {
        for (int i = 1; i <= address.getMaxAddressLineIndex(); i++) {

            if (address.getAddressLine(i).equalsIgnoreCase(address.getCountryName())) {
                continue;
            }

            sb.append(',');
            sb.append(' ');
            sb.append(address.getAddressLine(i));
        }
    }

    return sb.toString();
}

From source file:Main.java

public static String locationToAddress(Location loc, Context context) {
    try {/*from w w  w  .j a  v a  2s . c o  m*/
        double latitude, longitude;
        String addressText = "";
        geocoder = new Geocoder(context);
        latitude = loc.getLatitude();
        longitude = loc.getLongitude();
        List<Address> list = geocoder.getFromLocation(latitude, longitude, 1);

        if (list != null && list.size() > 0) {
            Address address = list.get(0);
            addressText = String.format("%s, %s, %s",
                    address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                    address.getLocality(), address.getCountryName());
        }

        return addressText;
    } catch (IOException e) {
        Log.e(LogDavid, "ERROR:" + e.toString());
        return "";
    }
}

From source file:Main.java

public static String getCompleteAddressString(Context context, double LATITUDE, double LONGITUDE) {
    String strAdd = "";
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
    try {//  ww  w. ja  v a2 s  .c  o m
        List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
        if (addresses != null) {
            Address returnedAddress = addresses.get(0);
            StringBuilder strReturnedAddress = new StringBuilder("");

            for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
                strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
            }
            strAdd = strReturnedAddress.toString();
            Log.w("My Current loction address", "" + strReturnedAddress.toString());
        } else {
            Log.w("My Current loction address", "No Address returned!");
        }

    } catch (Exception e) {
        e.printStackTrace();
        Log.w("My Current loction address", "Canont get Address!");
    }
    return strAdd;
}

From source file:Main.java

public static String getAddressString(Address address) {
    if (address.getMaxAddressLineIndex() == -1) {
        return null;
    }//from   w w  w.  ja v  a  2 s  .c o  m
    StringBuilder addressStringBuilder = new StringBuilder();
    for (int i = 0; i <= address.getMaxAddressLineIndex(); i++) {
        addressStringBuilder.append(address.getAddressLine(i));
        if (i != address.getMaxAddressLineIndex()) {
            addressStringBuilder.append(", ");
        }
    }
    return addressStringBuilder.toString();
}

From source file:grandroid.geo.Geocoder.java

public static String convertAddress(double lat, double lng) throws Exception {
    List<Address> adds = getFromLocation(lat, lng, 1);
    if (adds == null || adds.isEmpty()) {
        throw new Exception("no address can be found");
    } else {/*from w  ww.j av  a2 s . c om*/
        Address add = adds.get(0);
        if (add.getFeatureName() == null) {
            return add.getAdminArea() + add.getLocality() + add.getAddressLine(0);
        } else {
            return add.getFeatureName();
        }
    }
}

From source file:net.giovannicapuano.galax.util.Utils.java

/**
 * Convert geographic coordinates to a human-readable address.
 *//* w  w w . j a v  a  2  s.  c om*/
public static String coordinatesToAddress(double latitude, double longitude, Context context) {
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
    if (!Geocoder.isPresent())
        return "";

    try {
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);

        if (addresses != null && !addresses.isEmpty()) {
            Address returnedAddress = addresses.get(0);
            StringBuilder address = new StringBuilder();
            for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); ++i)
                address.append(returnedAddress.getAddressLine(i)).append("\n");
            return address.toString();
        } else {
            return "";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

From source file:grandroid.geo.Geocoder.java

public static String convertAddress(double lat, double lng, boolean nation, boolean city, boolean district,
        boolean street) throws Exception {
    List<Address> adds = getFromLocation(lat, lng, 1);
    if (adds == null || adds.isEmpty()) {
        throw new Exception("no address can be found");
    } else {//from   w w  w. ja  v a  2 s .  c  om
        Address add = adds.get(0);
        StringBuilder sb = new StringBuilder();
        if (nation) {
            sb.append(add.getCountryName());
        }
        if (city) {
            sb.append(add.getAdminArea());
        }
        if (district) {
            sb.append(add.getLocality());
        }
        if (street) {
            sb.append(add.getAddressLine(0));
        }
        return sb.toString();
    }
}

From source file:fr.gotorennes.AbstractMapActivity.java

public static Location getLocation(Context context, String address) {
    if ("".equals(address.trim())) {
        android.location.Location l = LocationUtils.getLocation(context);
        return l != null
                ? new Location(l.getLatitude(), l.getLongitude(), context.getString(R.string.positionActuelle))
                : null;/*w  w w  . ja va2  s .  c  om*/
    }

    Geocoder geocoder = new Geocoder(context);
    try {
        List<Address> addresses = geocoder.getFromLocationName(address + ",35 ille et vilaine", 1);
        if (addresses != null && !addresses.isEmpty()) {
            Address foundAddress = addresses.get(0);
            return new Location(foundAddress.getLatitude(), foundAddress.getLongitude(),
                    foundAddress.getAddressLine(0));
        }
    } catch (Exception ex) {
        Log.e("GoToRennes", ex.getMessage());
    }
    return null;
}