List of usage examples for android.location Address getMaxAddressLineIndex
public int getMaxAddressLineIndex()
From source file:Main.java
public static String getAddressString(Address address) { if (address.getMaxAddressLineIndex() == -1) { return null; }// ww w. j a v a 2s.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:Main.java
public static String extractAddressLines(Address address) { String resultAddress = null;//from ww w.j a va 2s . 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 boolean isValidAddress(@Nullable final Address address) { if (address == null) { return false; }/* ww w . j a v a 2 s. c om*/ if (address.getMaxAddressLineIndex() <= 0) { return false; } return true; }
From source file:Main.java
public static String locationToAddress(Location loc, Context context) { try {// w w w . jav a 2 s.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 {//w w w. ja v a 2s . com 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 @Nullable String getAddressStringOneLine(@Nullable final Address address) { if (address == null) { return null; }// w ww . j a v a 2s . 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:net.giovannicapuano.galax.util.Utils.java
/** * Convert geographic coordinates to a human-readable address. *//*from w ww .jav 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:com.mk4droid.IMC_Utils.GEO.java
public static String ConvertGeoPointToAddress(LatLng pt, Context ctx) { Address maddress = null; try {/*from ww w.j ava 2s. c o m*/ Geocoder geocoder = new Geocoder(ctx, Locale.getDefault()); List<Address> list = geocoder.getFromLocation(pt.latitude, pt.longitude, 1); if (list != null && list.size() > 0) { maddress = list.get(0); } } catch (Exception e) { Log.e(Constants_API.TAG, "Gecoder falied: I will try with REST"); new RevGEO_Try2_Asynch(pt.latitude, pt.longitude).execute(); } String Address_STR = ""; if (maddress != null) { for (int i = 0; i < maddress.getMaxAddressLineIndex(); i++) Address_STR += maddress.getAddressLine(i) + ", "; Address_STR += maddress.getCountryName(); } return Address_STR; }
From source file:com.cloudbees.gasp.activity.GaspLocationsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_locations); GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); LocationManager locationManager;/*from w w w . j a v a 2 s. co m*/ String svcName = Context.LOCATION_SERVICE; locationManager = (LocationManager) getSystemService(svcName); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); Log.i(TAG, "CURRENT LOCATION"); Log.i(TAG, "Latitude = " + location.getLatitude()); Log.i(TAG, "Longitude = " + location.getLongitude()); if (location != null) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); Geocoder gc = new Geocoder(this, Locale.getDefault()); if (!Geocoder.isPresent()) Log.i(TAG, "No geocoder available"); else { try { List<Address> addresses = gc.getFromLocation(latitude, longitude, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); for (int i = 0; i < address.getMaxAddressLineIndex(); i++) sb.append(address.getAddressLine(i)).append(" "); sb.append(address.getLocality()).append(""); sb.append(address.getPostalCode()).append(" "); sb.append(address.getCountryName()); } Log.i(TAG, "Address: " + sb.toString()); } catch (IOException e) { Log.d(TAG, "IOException getting address from geocoder", e); } } } map.setMyLocationEnabled(true); LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude()); CameraPosition cameraPosition = new CameraPosition.Builder().target(myLocation).zoom(16).bearing(0).tilt(0) .build(); map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); new LocationMapper().execute(); }
From source file:com.vishwa.pinit.LocationSuggestionProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { switch (uriMatcher.match(uri)) { case SEARCH_SUGGEST: String query = uri.getLastPathSegment(); MatrixCursor cursor = new MatrixCursor(SEARCH_SUGGEST_COLUMNS, 1); if (Geocoder.isPresent()) { try { mGeocoder = new Geocoder(getContext(), Locale.ENGLISH); List<Address> addressList = mGeocoder.getFromLocationName(query, 5); for (int i = 0; i < addressList.size(); i++) { Address address = addressList.get(i); StringBuilder fullAddress = new StringBuilder(); for (int j = 1; j < address.getMaxAddressLineIndex(); j++) { fullAddress.append(address.getAddressLine(j)); }//from w w w . j ava2s . c om cursor.addRow(new String[] { Integer.toString(i), address.getAddressLine(0).toString(), fullAddress.toString(), address.getLatitude() + "," + address.getLongitude() }); } return cursor; } catch (IllegalArgumentException e) { return getLocationSuggestionsUsingAPI(query, cursor); } catch (IOException e) { return getLocationSuggestionsUsingAPI(query, cursor); } } default: throw new IllegalArgumentException("Unknown Uri: " + uri); } }