Java Code Examples for android.location.Address#getAddressLine()
The following examples show how to use
android.location.Address#getAddressLine() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocationHelper.java From Bus-Tracking-Parent with GNU General Public License v3.0 | 6 votes |
@Nullable public static String getLocationName(Context context, double lat, double lon) { Geocoder g = new Geocoder(context); try { Address address = g.getFromLocation(lat, lon, 1).get(0); String address_line = ""; int max_address = address.getMaxAddressLineIndex(); for (int i = 0; i < max_address; i++) { address_line += address.getAddressLine(i) + " "; } return address_line; } catch (IOException | IndexOutOfBoundsException e) { } return null; }
Example 2
Source File: MapActions.java From PocketMaps with MIT License | 6 votes |
private OnClickAddressListener createPosSelectedListener(final boolean isStartP) { OnClickAddressListener callbackListener = new OnClickAddressListener() { @Override public void onClick(Address addr) { GeoPoint newPos = new GeoPoint(addr.getLatitude(), addr.getLongitude()); String fullAddress = ""; for (int i=0; i<5; i++) { String curAddr = addr.getAddressLine(i); if (curAddr == null || curAddr.isEmpty()) { continue; } if (!fullAddress.isEmpty()) { fullAddress = fullAddress + ", "; } fullAddress = fullAddress + curAddr; } doSelectCurrentPos(newPos, fullAddress, isStartP); } }; return callbackListener; }
Example 3
Source File: MapViewHandler.java From PowerSwitch_Android with GNU General Public License v3.0 | 6 votes |
/** * Find a address description for a given coordinate * * @param latLng coordinate * @return address description * @throws AddressNotFoundException */ public String findAddress(LatLng latLng) throws AddressNotFoundException { /* get latitude and longitude from the address */ Geocoder geoCoder = new Geocoder(context, Locale.getDefault()); try { List<Address> addresses = geoCoder.getFromLocation(latLng.latitude, latLng.longitude, 5); if (addresses.size() > 0) { Address address = addresses.get(0); String addressAsString = address.getAddressLine(0); Log.d("Address; ", addressAsString); return addressAsString; } else { throw new AddressNotFoundException("latitude: " + latLng.latitude + ", longitude: " + latLng.longitude); } } catch (IOException e) { Log.e(e); } return null; }
Example 4
Source File: PlacePickerActivity.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private static @NonNull String addressToShortString(@Nullable Address address) { if (address == null) return ""; String addressLine = address.getAddressLine(0); String[] split = addressLine.split(","); if (split.length >= 3) { return split[1].trim() + ", " + split[2].trim(); } else if (split.length == 2) { return split[1].trim(); } else return split[0].trim(); }
Example 5
Source File: LocationUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 根据经纬度获取所在街道 * @param latitude 纬度 * @param longitude 经度 * @return 所在街道 */ public static String getStreet(final double latitude, final double longitude) { Address address = getAddress(latitude, longitude); try { return address == null ? "unknown" : address.getAddressLine(0); } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "getStreet"); } return "unknown"; }
Example 6
Source File: LocationReader.java From MuslimMateAndroid with GNU General Public License v3.0 | 5 votes |
public boolean locationToAddress(double latitude, double longitude) { Geocoder geocoder = new Geocoder(this.context, Locale.getDefault()); try { List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); if (addresses != null) { Address returnedAddress = addresses.get(0); StringBuilder strReturnedAddress = new StringBuilder(""); locationInfo.clear(); String city = returnedAddress.getAdminArea(); if(city==null) city = returnedAddress.getLocality(); locationInfo.put("country", returnedAddress.getCountryName()); locationInfo.put("countrycode", returnedAddress.getCountryCode().toLowerCase()); locationInfo.put("latitude", ""+returnedAddress.getLatitude()); locationInfo.put("longitude", ""+returnedAddress.getLongitude()); if(city!=null)locationInfo.put("city", ""+city); String address = ""; for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) { address = address + returnedAddress.getAddressLine(i) + "\n"; } locationInfo.put("address", address); return true; } else { } } catch (Exception e) { } return false; }
Example 7
Source File: AddressGeocoder.java From financisto with GNU General Public License v2.0 | 5 votes |
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(); }
Example 8
Source File: MainActivity.java From RxGps with Apache License 2.0 | 5 votes |
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; }
Example 9
Source File: TrackNameUtils.java From mytracks with Apache License 2.0 | 5 votes |
/** * Gets the reverse geo coding string for a location. * * @param context the context * @param location the location */ private static String getReverseGeoCoding(Context context, Location location) { if (location == null || !ApiAdapterFactory.getApiAdapter().isGeoCoderPresent()) { return null; } Geocoder geocoder = new Geocoder(context); try { List<Address> addresses = geocoder.getFromLocation( location.getLatitude(), location.getLongitude(), 1); if (addresses.size() > 0) { Address address = addresses.get(0); int lines = address.getMaxAddressLineIndex(); if (lines > 0) { return address.getAddressLine(0); } String featureName = address.getFeatureName(); if (featureName != null) { return featureName; } String thoroughfare = address.getThoroughfare(); if (thoroughfare != null) { return thoroughfare; } String locality = address.getLocality(); if (locality != null) { return locality; } } } catch (IOException e) { // Can safely ignore } return null; }
Example 10
Source File: ChronometerView.java From open-quartz with Apache License 2.0 | 5 votes |
/** * Update the value of the chronometer. */ private void updateText() { long millis = SystemClock.elapsedRealtime() - mBaseMillis; millis %= TimeUnit.HOURS.toMillis(1); millis %= TimeUnit.MINUTES.toMillis(1); millis = (millis % TimeUnit.SECONDS.toMillis(1)) / 10; location = getLastLocation(getContext()); if (location != null) { text = String.format("Lat:\t %f Long:\t %f\n" + "Alt:\t %f Bearing:\t %f", location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getBearing()); if (geocoder != null) { try { final List<Address> addresses = geocoder .getFromLocation(location.getLatitude(), location.getLongitude(), 10); for (Address address : addresses) { text += "\n" + address.getAddressLine(0); } } catch (Exception ignored) { } } } mCentiSecondView.setText(text + " " + millis + " "); if (mChangeListener != null) { mChangeListener.onChange(); } }
Example 11
Source File: PlacePickerActivity.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private static @NonNull String addressToString(@Nullable Address address) { return address != null ? address.getAddressLine(0) : ""; }
Example 12
Source File: StartRide.java From kute with Apache License 2.0 | 4 votes |
public void reverseGeocodeSource(final Location location,final Integer index){ Runnable r=new Runnable() { @Override public void run() { Log.i("ReverseGeocodeFirebase","Started runnable"); String address="null"; Geocoder geocoder= new Geocoder(getBaseContext(), Locale.ENGLISH); Double latitude=location.getLatitude(); Double longitude=location.getLongitude(); try { //Place your latitude and longitude List<Address> addresses = geocoder.getFromLocation(latitude,longitude,1); if(addresses != null) { Address fetchedAddress = addresses.get(0); StringBuilder strAddress = new StringBuilder(); for(int i=0; i<fetchedAddress.getMaxAddressLineIndex(); i++) { strAddress.append(fetchedAddress.getAddressLine(i)).append("\n"); } address=strAddress.toString(); source_address=address; source_string=fetchedAddress.getAddressLine(1); Log.d("ReverseGeocodeFirebase","The current Address is"+ address); Log.d("ReverseGeocodeFirebase","The current source string is"+ source_string); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(getApplicationContext(),"Could not get address..!", Toast.LENGTH_LONG).show(); } } }; reverse_geocode_handler.post(r); }
Example 13
Source File: LocationUtils.java From Android-UtilCode with Apache License 2.0 | 2 votes |
/** * 根据经纬度获取所在街道 * * @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); }
Example 14
Source File: RxLocationTool.java From RxTools-master with Apache License 2.0 | 2 votes |
/** * 根据经纬度获取所在街道 * * @param context 上下文 * @param latitude 纬度 * @param longitude 经度 * @return 所在街道 */ public static String getStreet(Context context, double latitude, double longitude) { Address address = getAddress(context, latitude, longitude); return address == null ? "unknown" : address.getAddressLine(0); }
Example 15
Source File: LocationUtils.java From AndroidUtilCode with Apache License 2.0 | 2 votes |
/** * 根据经纬度获取所在街道 * * @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); }