public AddressAssert hasCountryName(String name) { isNotNull(); String actualName = actual.getCountryName(); assertThat(actualName) // .overridingErrorMessage("Expected country name <%s> but was <%s>.", name, actualName) // .isEqualTo(name); return this; }
private String getAddress(double latitude, double longitude) { StringBuilder result = new StringBuilder(); try { Geocoder geocoder = new Geocoder(this, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) { Address address = addresses.get(0); result.append(address.getLocality()).append("\n"); result.append(address.getCountryName()); } } catch (IOException e) { Log.e("tag", e.getMessage()); } return result.toString(); }
if (null != listAddresses && listAddresses.size() > 0) { try { returnLocation.append(listAddresses.get(0).getCountryName()); returnLocation.append(" "); returnLocation.append(listAddresses.get(0).getAdminArea());
if (null != listAddresses && listAddresses.size() > 0) { try { returnLocation.append(listAddresses.get(0).getCountryName()); returnLocation.append(" "); returnLocation.append(listAddresses.get(0).getAdminArea());
/** * 根据经纬度获取所在国家 * * @param latitude 纬度 * @param longitude 经度 * @return {@link Address} */ public String getCountryName(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getCountryName(); }
/** * 根据经纬度获取所在国家 * * @param latitude 纬度 * @param longitude 经度 * @return 所在国家 */ public static String getCountryName(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getCountryName(); }
/** * 根据经纬度获取所在国家 * * @param latitude 纬度 * @param longitude 经度 * @return 所在国家 */ public static String getCountryName(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getCountryName(); }
/** * 根据经纬度获取所在国家 * * @param latitude 纬度 * @param longitude 经度 * @return 所在国家 */ public static String getCountryName(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getCountryName(); }
/** * 根据经纬度获取所在国家 * * @param latitude 纬度 * @param longitude 经度 * @return 所在国家 */ public static String getCountryName(double latitude, double longitude) { Address address = getAddress(latitude, longitude); return address == null ? "unknown" : address.getCountryName(); }
/** * Try to get CountryName * @return null or postalCode */ public String getCountryName(Context context) { List<Address> addresses = getGeocoderAddress(context); if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); String countryName = address.getCountryName(); return countryName; } else { return null; } }
Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault()); Address address; List<Address> list; list = geocoder.getFromLocation(latitude,longitude,1);//33.64600, 72.96115 address = list.get(0); String cityname = address.getLocality(); String countryname = address.getCountryName(); Log.d("cityname",cityname.toString()); Log.d("countryname",countryname.toString());
private void getAndWriteAddressFromGeocoder(String latitude, String longitude, SharedPreferences.Editor editor) { Geocoder geocoder = new Geocoder(this, Locale.getDefault()); try { String latitudeEn = latitude.replace(",", "."); String longitudeEn = longitude.replace(",", "."); List<Address> addresses = geocoder.getFromLocation(Double.parseDouble(latitudeEn), Double.parseDouble(longitudeEn), 1); if ((addresses != null) && (addresses.size() > 0)) { editor.putString(Constants.APP_SETTINGS_GEO_CITY, addresses.get(0).getLocality()); editor.putString(Constants.APP_SETTINGS_GEO_COUNTRY_NAME, addresses.get(0).getCountryName()); } } catch (IOException | NumberFormatException ex) { Log.e(TAG, "Unable to get address from latitude and longitude", ex); } }
public AddressAssert hasCountryName(String name) { isNotNull(); String actualName = actual.getCountryName(); assertThat(actualName) // .overridingErrorMessage("Expected country name <%s> but was <%s>.", name, actualName) // .isEqualTo(name); return this; }
List<Address> addresses = new Geocoder(<CurrentActivityName>.this,Locale.getDefault()).getFromLocation(cur_lat, cur_lon, 1); Address addr= addresses.get(0); String Country=addr.getCountryName(); String State=addr.getSubAdminArea(); String City=addr.getLocality();
private void getAndWriteAddressFromGeocoder(String latitude, String longitude, SharedPreferences.Editor editor) { Geocoder geocoder = new Geocoder(this, Locale.getDefault()); try { String latitudeEn = latitude.replace(",", "."); String longitudeEn = longitude.replace(",", "."); List<Address> addresses = geocoder.getFromLocation(Double.parseDouble(latitudeEn), Double.parseDouble(longitudeEn), 1); if ((addresses != null) && (addresses.size() > 0)) { editor.putString(Constants.APP_SETTINGS_GEO_CITY, addresses.get(0).getLocality()); editor.putString(Constants.APP_SETTINGS_GEO_DISTRICT_OF_CITY, addresses.get(0).getSubLocality()); editor.putString(Constants.APP_SETTINGS_GEO_COUNTRY_NAME, addresses.get(0).getCountryName()); } } catch (IOException | NumberFormatException ex) { Log.e(TAG, "Unable to get address from latitude and longitude", ex); } }
Address address = addresses.get(0); String addressText = String.format( "%s, %s, %s", // If there's a street address, add it address.getMaxAddressLineIndex() > 0 ? ddress.getAddressLine(0) : "", // Locality is usually a city address.getLocality(), // The country of the address address.getCountryName()); return addressText;
String addressString; try { Geocoder geocoder = new Geocoder(this, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(lat, lng, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); sb.append(address.getLocality()).append("\n"); sb.append(address.getCountryName()); } addressString = sb.toString(); Log.e("Address from lat,long ;", addressString); } catch (IOException e) {} }
Geocoder gc = new Geocoder(context); if(gc.isPresent()){ List<Address> list = gc.getFromLocation(37.42279, -122.08506,1); Address address = list.get(0); StringBuffer str = new StringBuffer(); str.append("Name: " + address.getLocality() + "\n"); str.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n"); str.append("Admin Area: " + address.getAdminArea() + "\n"); str.append("Country: " + address.getCountryName() + "\n"); str.append("Country Code: " + address.getCountryCode() + "\n"); String strAddress = str.toString(); }
StringBuilder _homeAddress = null; try{ _homeAddress = new StringBuilder(); Address address = null; List<Address> addresses = _coder.getFromLocation(_lat,_lon,1); for(int index=0; index<addresses.size(); ++index) { address = addresses.get(index); _homeAddress.append("Name: " + address.getLocality() + "\n"); _homeAddress.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n"); _homeAddress.append("Admin Area: " + address.getAdminArea() + "\n"); _homeAddress.append("Country: " + address.getCountryName() + "\n"); _homeAddress.append("Country Code: " + address.getCountryCode() + "\n"); _homeAddress.append("Latitude: " + address.getLatitude() + "\n"); _homeAddress.append("Longitude: " + address.getLongitude() + "\n\n"); } } catch(Exception e){ }
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(); } }