List of usage examples for android.location Address getCountryName
public String getCountryName()
From source file:Main.java
public static String locationToAddress(Location loc, Context context) { try {/* ww w . j a v a2 s . co 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: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 www. java 2 s . c o m 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:Main.java
public static @Nullable String getAddressStringOneLine(@Nullable final Address address) { if (address == null) { return null; }//from ww w. j a va2 s . c o m 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:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java
private static JSONObject buildJsonAddress(Address address) throws JSONException { JSONObject result = new JSONObject(); result.put("admin_area", address.getAdminArea()); result.put("country_code", address.getCountryCode()); result.put("country_name", address.getCountryName()); result.put("feature_name", address.getFeatureName()); result.put("phone", address.getPhone()); result.put("locality", address.getLocality()); result.put("postal_code", address.getPostalCode()); result.put("sub_admin_area", address.getSubAdminArea()); result.put("thoroughfare", address.getThoroughfare()); result.put("url", address.getUrl()); return result; }
From source file:ca.itquality.patrol.util.weather.YahooWeather.java
public static String addressToPlaceName(final Address address) { String result = ""; if (address.getLocality() != null) { result += address.getLocality(); result += " "; }/*from w w w. j av a 2s . c o m*/ if (address.getAdminArea() != null) { result += address.getAdminArea(); result += " "; } if (address.getCountryName() != null) { result += address.getCountryName(); result += " "; } return result; }
From source file:com.mk4droid.IMC_Utils.GEO.java
public static String ConvertGeoPointToAddress(LatLng pt, Context ctx) { Address maddress = null; try {/*w ww. ja va2 s . 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.javielinux.fragments.SearchGeoFragment.java
@Override public void onResults(BaseResponse response) { GetGeolocationAddressResponse result = (GetGeolocationAddressResponse) response; if (result.getSingleResult()) { if (result.getAddressList().size() > 0) { Address address = result.getAddressList().get(0); String text = address.getAddressLine(0); if (address.getCountryName() != null) text = text + " (" + address.getCountryName() + ")"; place.setText(text);/*from w ww. j ava2 s. c o m*/ latitude.setText(String.valueOf(address.getLatitude())); longitude.setText(String.valueOf(address.getLongitude())); } } else { address_list.clear(); for (Address address : result.getAddressList()) { address_list.add(address); } address_adapter.notifyDataSetChanged(); } }
From source file:nl.hnogames.domoticz.UI.LocationDialog.java
private void setAddressData(Address foundLocation) { String address = foundLocation.getAddressLine(0) + ", " + foundLocation.getLocality(); resolvedAddress.setText(address);/*from w w w. j a va2 s .co m*/ resolvedCountry.setText(foundLocation.getCountryName()); }
From source file:nl.hnogames.domoticz.Adapters.LocationAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; int layoutResourceId; final LocationInfo mLocationInfo = data.get(position); holder = new ViewHolder(); layoutResourceId = R.layout.geo_row_location; LayoutInflater inflater = ((Activity) context).getLayoutInflater(); convertView = inflater.inflate(layoutResourceId, parent, false); if (mSharedPrefs.darkThemeEnabled()) { (convertView.findViewById(R.id.row_wrapper)) .setBackground(ContextCompat.getDrawable(context, R.drawable.bordershadowdark)); (convertView.findViewById(R.id.row_global_wrapper)) .setBackgroundColor(ContextCompat.getColor(context, R.color.background_dark)); if ((convertView.findViewById(R.id.remove_button)) != null) (convertView.findViewById(R.id.remove_button)) .setBackground(ContextCompat.getDrawable(context, R.drawable.button_status_dark)); }//from w w w .j a v a 2s . c o m holder.enable = (CheckBox) convertView.findViewById(R.id.enableSwitch); holder.name = (TextView) convertView.findViewById(R.id.location_name); holder.radius = (TextView) convertView.findViewById(R.id.location_radius); holder.country = (TextView) convertView.findViewById(R.id.location_country); holder.address = (TextView) convertView.findViewById(R.id.location_address); holder.connectedSwitch = (TextView) convertView.findViewById(R.id.location_connectedSwitch); holder.remove = (Button) convertView.findViewById(R.id.remove_button); if (mLocationInfo.getAddress() != null) { Address address = mLocationInfo.getAddress(); String addressString; String countryString; if (address != null) { addressString = address.getAddressLine(0) + ", " + address.getLocality(); countryString = address.getCountryName(); } else { addressString = context.getString(R.string.unknown); countryString = context.getString(R.string.unknown); } holder.address.setText(addressString); holder.country.setText(countryString); } holder.name.setText(mLocationInfo.getName()); holder.radius.setText(context.getString(R.string.radius) + ": " + mLocationInfo.getRadius()); if (!UsefulBits.isEmpty(mLocationInfo.getSwitchName())) { holder.connectedSwitch .setText(context.getString(R.string.connectedSwitch) + ": " + mLocationInfo.getSwitchName()); } else if (mLocationInfo.getSwitchIdx() > 0) { holder.connectedSwitch .setText(context.getString(R.string.connectedSwitch) + ": " + mLocationInfo.getSwitchIdx()); } else { holder.connectedSwitch.setText( context.getString(R.string.connectedSwitch) + ": " + context.getString(R.string.not_available)); } if (!UsefulBits.isEmpty(mLocationInfo.getValue())) holder.connectedSwitch.setText(holder.connectedSwitch.getText() + " - " + mLocationInfo.getValue()); holder.remove.setId(mLocationInfo.getID()); holder.remove.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { LocationInfo removeLocation = null; for (LocationInfo l : data) { if (l.getID() == v.getId()) { removeLocation = l; } } if (removeLocation != null) handleRemoveButtonClick(removeLocation); } }); holder.enable.setId(mLocationInfo.getID()); holder.enable.setChecked(mLocationInfo.getEnabled()); holder.enable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { for (LocationInfo locationInfo : data) { if (locationInfo.getID() == buttonView.getId()) { if (!handleEnableChanged(locationInfo, holder.enable.isChecked())) { buttonView.setChecked(false); } else { buttonView.setChecked(true); } break; } } } }); convertView.setTag(holder); return convertView; }
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;/* www. j a v a 2 s . c o 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(); }