List of usage examples for android.location Address getAddressLine
public String getAddressLine(int index)
From source file:com.mk4droid.IMC_Utils.GEO.java
public static String ConvertGeoPointToAddress(LatLng pt, Context ctx) { Address maddress = null; try {//from w ww. j a v a2 s .co 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.grottworkshop.gwswizardpager.ui.GeoFragment.java
private void updateLocationLabel(final String locationString) { String[] coordinateStrings = locationString.split(","); final double latitude = Double.parseDouble(coordinateStrings[0]); final double longitude = Double.parseDouble(coordinateStrings[1]); new AsyncTask<Void, Void, String>() { protected void onPreExecute() { progressBar.setVisibility(View.VISIBLE); }/*from www. j av a 2s.c o m*/ @Override protected String doInBackground(Void... params) { try { List<Address> locationList = mGeocoder.getFromLocation(latitude, longitude, 1); if (locationList != null && locationList.size() > 0) { Address address = locationList.get(0); return address.getAddressLine(0); } } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String result) { super.onPostExecute(result); if (!TextUtils.isEmpty(result)) { textViewLocation.setText(getString(R.string.geo_status_location, result, locationString)); } else { textViewLocation.setText(latitude + "," + longitude); } progressBar.setVisibility(View.GONE); } }.execute(); }
From source file:nl.hnogames.domoticz.UI.LocationDialog.java
private void setAddressData(Address foundLocation) { String address = foundLocation.getAddressLine(0) + ", " + foundLocation.getLocality(); resolvedAddress.setText(address);/* w w w .j a va 2 s .c o m*/ resolvedCountry.setText(foundLocation.getCountryName()); }
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;/* w ww. j av a2s.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:self.yue.vehicletracker.ui.history.HistoryDetailActivity.java
private void getLocationAddress(double latitude, double longitude, final boolean isStartLocation) { new AsyncTask<LatLng, Void, Address>() { @Override/*w w w .j a v a2 s.co m*/ protected Address doInBackground(LatLng... params) { try { List<Address> addresses = mGeocoder.getFromLocation(params[0].latitude, params[0].longitude, 1); if (addresses != null && addresses.size() > 0) return addresses.get(0); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Address address) { if (address != null) { String addressText = String.format("%s", address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : getString(R.string.unknown_location)); if (isStartLocation) { mTextStartLocation.setText(addressText); } else { mTextEndLocation.setText(addressText); } } else { if (isStartLocation) { mTextStartLocation.setText("Unknown location"); } else { mTextEndLocation.setText("Unknown location"); } } } }.execute(new LatLng(latitude, longitude)); }
From source file:org.microg.gms.ui.PlacePickerActivity.java
@Override public void onMapEvent(Event event, MapPosition position) { place.viewport = GmsMapsTypeHelper.toLatLngBounds(mapView.map().viewport().getBBox(null, 0)); resultIntent.putExtra(LocationConstants.EXTRA_FINAL_BOUNDS, place.viewport); place.latLng = GmsMapsTypeHelper.toLatLng(position.getGeoPoint()); place.name = ""; place.address = ""; updateInfoText();/*w w w.j av a 2 s . c o m*/ if (geocoderInProgress.compareAndSet(false, true)) { new Thread(new Runnable() { @Override public void run() { try { LatLng ll = null; while (ll != place.latLng) { ll = place.latLng; Thread.sleep(1000); } Geocoder geocoder = new Geocoder(PlacePickerActivity.this); List<Address> addresses = geocoder.getFromLocation(place.latLng.latitude, place.latLng.longitude, 1); if (addresses != null && !addresses.isEmpty() && addresses.get(0).getMaxAddressLineIndex() > 0) { Address address = addresses.get(0); StringBuilder sb = new StringBuilder(address.getAddressLine(0)); for (int i = 1; i < address.getMaxAddressLineIndex(); ++i) { if (i == 1 && sb.toString().equals(address.getFeatureName())) { sb = new StringBuilder(address.getAddressLine(i)); continue; } sb.append(", ").append(address.getAddressLine(i)); } if (place.latLng == ll) { place.address = sb.toString(); place.name = address.getFeatureName(); runOnUiThread(new Runnable() { @Override public void run() { updateInfoText(); } }); } } } catch (Exception ignored) { Log.w(TAG, ignored); } finally { geocoderInProgress.lazySet(false); } } }).start(); } }
From source file:de.j4velin.wifiAutoOff.Locations.java
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { if (requestCode == REQUEST_LOCATION) { if (resultCode == RESULT_OK) { LatLng location = data.getParcelableExtra("location"); String locationName = "UNKNOWN"; if (Geocoder.isPresent()) { Geocoder gc = new Geocoder(this); try { List<Address> result = gc.getFromLocation(location.latitude, location.longitude, 1); if (result != null && !result.isEmpty()) { Address address = result.get(0); locationName = address.getAddressLine(0); if (address.getLocality() != null) { locationName += ", " + address.getLocality(); }/* www .j av a 2s . c o m*/ } } catch (IOException e) { if (BuildConfig.DEBUG) Logger.log(e); e.printStackTrace(); } } Database db = Database.getInstance(this); db.addLocation(locationName, location); db.close(); locations.add(new Location(locationName, location)); mAdapter.notifyDataSetChanged(); } } else if (requestCode == REQUEST_BUY) { if (resultCode == RESULT_OK) { if (data.getIntExtra("RESPONSE_CODE", 0) == 0) { try { JSONObject jo = new JSONObject(data.getStringExtra("INAPP_PURCHASE_DATA")); PREMIUM_ENABLED = jo.getString("productId").equals("de.j4velin.wifiautomatic.billing.pro") && jo.getString("developerPayload").equals(getPackageName()); getSharedPreferences("settings", Context.MODE_PRIVATE).edit() .putBoolean("pro", PREMIUM_ENABLED).commit(); if (PREMIUM_ENABLED) { Toast.makeText(this, "Thank you!", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { if (BuildConfig.DEBUG) Logger.log(e); Toast.makeText(this, e.getClass().getName() + ": " + e.getMessage(), Toast.LENGTH_LONG) .show(); } } } } else { super.onActivityResult(requestCode, resultCode, data); } }
From source file:com.pk.ubulance.Activity.DisplayDriverActivity.java
public String getLocationName(Context mContext, Double latitude, Double longitude) { Geocoder myLocation = new Geocoder(mContext, Locale.getDefault()); List<Address> myList = null; try {//from w w w . ja v a2s. c om myList = myLocation.getFromLocation(latitude, longitude, 1); } catch (IOException e) { e.printStackTrace(); } Address address = (Address) myList.get(0); String addressStr = ""; addressStr += address.getAddressLine(0) + ", "; addressStr += address.getAddressLine(1) + ", "; addressStr += address.getAddressLine(2); Log.d("Ubulance", "Your Location: " + addressStr); return addressStr; }
From source file:com.hoccer.api.android.LinccLocationManager.java
public String getDisplayableAddress(Location location) { try {/*from w ww.ja v a 2 s .c om*/ Address address = getAddress(location); String addressLine = null; String info = " (~" + location.getAccuracy() + "m)"; if (location.getAccuracy() < 500) { addressLine = address.getAddressLine(0); } else { addressLine = address.getAddressLine(1); } addressLine = trimAddress(addressLine); return addressLine + info; } catch (Exception e) { return UNKNOWN_LOCATION_TEXT + " ~" + location.getAccuracy() + "m"; } }
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 ww w. j a v a 2s . 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(); } }