public AddressAssert hasAddressLine(int index, String line) { isNotNull(); String actualLine = actual.getAddressLine(index); assertThat(actualLine) // .overridingErrorMessage("Expected address line %s <%s> but was <%s>.", index, line, actualLine) // .isEqualTo(line); return this; }
/** * 根据经纬度获取所在街道 * * @param latitude 纬度 * @param longitude 经度 * @return {@link Address} */ public String getStreet(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getAddressLine(0); }
private String getAddressText(Address address) { String addressText = ""; final int maxAddressLineIndex = address.getMaxAddressLineIndex(); for (int i = 0; i <= maxAddressLineIndex; i++) { addressText += address.getAddressLine(i); if (i != maxAddressLineIndex) { addressText += "\n"; } } return addressText; }
/** * 根据经纬度获取所在街道 * * @param latitude 纬度 * @param longitude 经度 * @return 所在街道 */ public static String getStreet(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getAddressLine(0); }
/** * 根据经纬度获取所在街道 * * @param latitude 纬度 * @param longitude 经度 * @return 所在街道 */ public static String getStreet(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getAddressLine(0); }
/** * 根据经纬度获取所在街道 * * @param latitude 纬度 * @param longitude 经度 * @return 所在街道 */ public static String getStreet(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getAddressLine(0); }
public static String addressToString(Address address) { StringBuilder sb = new StringBuilder(); int max = address.getMaxAddressLineIndex(); for (int i = max; i >= 0; i--) { String line = address.getAddressLine(i); if (i < max) { sb.append(", "); } sb.append(line); } return sb.toString(); }
/** * 根据经纬度获取所在街道 * * @param latitude 纬度 * @param longitude 经度 * @return 所在街道 */ public static String getStreet(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getAddressLine(0); }
/** * Try to get AddressLine * @return null or addressLine */ public String getAddressLine(Context context) { List<Address> addresses = getGeocoderAddress(context); if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); String addressLine = address.getAddressLine(0); return addressLine; } else { return null; } }
public AddressAssert hasAddressLine(int index, String line) { isNotNull(); String actualLine = actual.getAddressLine(index); assertThat(actualLine) // .overridingErrorMessage("Expected address line %s <%s> but was <%s>.", index, line, actualLine) // .isEqualTo(line); return this; }
/** * Sends a resultCode and message to the receiver. */ private void deliverResultToReceiver(int resultCode, String message, Address address) { try { Bundle bundle = new Bundle(); bundle.putString(AppUtils.LocationConstants.RESULT_DATA_KEY, message); bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_AREA, address.getSubLocality()); bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_CITY, address.getLocality()); bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_STREET, address.getAddressLine(0)); mReceiver.send(resultCode, bundle); } catch (Exception e) { e.printStackTrace(); } }
@Override public String reverse(double latitude, double longitude) { if(!android.location.Geocoder.isPresent()) { Timber.e("geocoder is not present"); return null; } List<Address> addresses; try { addresses = geocoder.getFromLocation(latitude, longitude, 1); if ((addresses != null) && (addresses.size() > 0)) { StringBuilder g = new StringBuilder(); Address a = addresses.get(0); if (a.getAddressLine(0) != null) g.append(a.getAddressLine(0)); return g.toString(); } else { return "not available"; } } catch (Exception e) { return null; } }
private String getAddressFromLocation(Context context, Location location) { Geocoder geocoder = new Geocoder(context); try { double latitude = location.getLatitude(); double longitude = location.getLongitude(); SxbLog.d(TAG, "getAddressFromLocation->lat:" + latitude + ", long:" + longitude); List<Address> list = geocoder.getFromLocation(latitude, longitude, 1); if (list.size() > 0) { Address address = list.get(0); return address.getAddressLine(0); } } catch (IOException e) { } return ""; }
private void fetchLocation(Location location) { List<Address> addresses; Geocoder geocoder = new Geocoder(ctx, Locale.getDefault()); try { ADLocation adLocation=new ADLocation(); addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); adLocation.address= addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex() adLocation.city=addresses.get(0).getLocality(); adLocation.state= addresses.get(0).getAdminArea(); adLocation.country = addresses.get(0).getCountryName(); adLocation.pincode= addresses.get(0).getPostalCode(); adLocation.lat=location.getLatitude(); adLocation.longi=location.getLongitude(); locListener.whereIAM(adLocation); }catch (Exception e){ e.printStackTrace(); } }
private void geoLocate(){ Log.d(TAG, "geoLocate: geolocating"); String searchString = mSearchText.getText().toString(); Geocoder geocoder = new Geocoder(MapActivity.this); List<Address> list = new ArrayList<>(); try{ list = geocoder.getFromLocationName(searchString, 1); }catch (IOException e){ Log.e(TAG, "geoLocate: IOException: " + e.getMessage() ); } if(list.size() > 0){ Address address = list.get(0); Log.d(TAG, "geoLocate: found a location: " + address.toString()); //Toast.makeText(this, address.toString(), Toast.LENGTH_SHORT).show(); moveCamera(new LatLng(address.getLatitude(), address.getLongitude()), DEFAULT_ZOOM, address.getAddressLine(0)); } }
@Override protected String doInBackground(Void... params) { Geocoder geocoder = new Geocoder(AppMapActivity.this, Locale.getDefault()); List<Address> addresses = null; try { addresses = geocoder.getFromLocation(geoBean.getLat(), geoBean.getLon(), 1); } catch (IOException e) { cancel(true); } if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); StringBuilder builder = new StringBuilder(); int size = address.getMaxAddressLineIndex(); for (int i = 0; i < size; i++) { builder.append(address.getAddressLine(i)); } return builder.toString(); } return ""; }
@Override protected String doInBackground(Void... params) { Geocoder geocoder = new Geocoder(NearbyTimeLineActivity.this, Locale.getDefault()); List<Address> addresses = null; try { addresses = geocoder.getFromLocation(geoBean.getLat(), geoBean.getLon(), 1); } catch (IOException e) { cancel(true); } if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); StringBuilder builder = new StringBuilder(); int size = address.getMaxAddressLineIndex(); for (int i = 0; i < size; i++) { builder.append(address.getAddressLine(i)); } return builder.toString(); } return ""; }
public static String getStreetLocation(double latitude, double longitude) { try { final Geocoder geocoder = new Geocoder(xdrip.getAppContext(), Locale.getDefault()); final List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); UserError.Log.d(TAG, addresses.toString()); final String address = addresses.get(0).getAddressLine(0); UserError.Log.d(TAG, "Street address: " + address); return address; } catch (IndexOutOfBoundsException | NullPointerException e) { UserError.Log.e(TAG, "Couldn't isolate street address"); } catch (IOException e) { UserError.Log.e(TAG, "Location error (reboot sometimes helps fix geocoding): " + e); } return null; } }
public static String getStreetLocation(double latitude, double longitude) { try { final Geocoder geocoder = new Geocoder(xdrip.getAppContext(), Locale.getDefault()); final List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); UserError.Log.d(TAG, addresses.toString()); final String address = addresses.get(0).getAddressLine(0); UserError.Log.d(TAG, "Street address: " + address); return address; } catch (IndexOutOfBoundsException | NullPointerException e) { UserError.Log.e(TAG, "Couldn't isolate street address"); } catch (IOException e) { UserError.Log.e(TAG, "Location error (reboot sometimes helps fix geocoding): " + e); } return null; } }
@Override protected void onPostExecute(List<Address> addresses) { if (addresses == null || addresses.size() == 0) { Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show(); } // Adding Markers on Google Map for each matching address Address address = addresses.get(0); // Creating an instance of GeoPoint, to display in Google Map LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude()); String addressText = String.format("%s, %s", address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "", address.getCountryName()); markerOptions = new MarkerOptions(); markerOptions.position(latLng); markerOptions.title(addressText); map.addMarker(markerOptions); // Locate the first location map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 4)); } }