@Before public void setUp() throws Exception { Context context = ApplicationProvider.getApplicationContext(); geocoder = new Geocoder(context); }
Toast.makeText( getBaseContext(), "Location changed: Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show(); String longitude = "Longitude: " + loc.getLongitude(); Log.v(TAG, longitude); String latitude = "Latitude: " + loc.getLatitude(); Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault()); List<Address> addresses; try { addresses = gcd.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1); if (addresses.size() > 0) {
public LatLng getLocationFromAddress(Context context,String strAddress) { Geocoder coder = new Geocoder(context); List<Address> address; LatLng p1 = null; try { address = coder.getFromLocationName(strAddress, 5); if (address == null) { return null; } Address location = address.get(0); location.getLatitude(); location.getLongitude(); p1 = new LatLng(location.getLatitude(), location.getLongitude() ); } catch (Exception ex) { ex.printStackTrace(); } return p1; }
Geocoder gcd = new Geocoder(context, Locale.getDefault()); List<Address> addresses = gcd.getFromLocation(lat, lng, 1); if (addresses.size() > 0) { System.out.println(addresses.get(0).getLocality()); } else { // do your staff }
private void pointToLocation(String s) { Geocoder gc = new Geocoder(MapDemo.this, Locale.getDefault()); try { List<Address> addresses = gc.getFromLocationName( s, 5); String add = ""; if (addresses.size() > 0) { point = new GeoPoint( (int) (addresses.get(0).getLatitude() * 1E6), (int) (addresses.get(0).getLongitude() * 1E6)); controller.animateTo(point); } } catch (IOException e) { Toast.makeText(MapDemo.this, "Location not found", Toast.LENGTH_LONG).show(); } }
double latiTude = 10.3929393; double longiTude = 150.93984884; Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault()); GeoPoint p= new GeoPoint((int) (latiTude * 1E6), (int) (longiTude * 1E6)); List<Address> address = geocoder.getFromLocation( p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6, 1); if (address.size() > 0) { String addressFroLatLong= ""; for (int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++) { addressFroLatLong+= address.get(0).getAddressLine(i) + "\n"; } }
Geocoder geocoder = new Geocoder(HomeActivity.mContext, Locale.getDefault()); try { List<Address> addresses = geocoder.getFromLocation(lat, lng, 1); Address obj = addresses.get(0); String add = obj.getAddressLine(0); GUIStatics.currentAddress = obj.getSubAdminArea() + "," + obj.getAdminArea(); GUIStatics.latitude = obj.getLatitude(); GUIStatics.longitude = obj.getLongitude();
private void setUpMap() throws IOException { Geocoder geo = new Geocoder(getApplicationContext(), Locale.getDefault()); List<Address> addressList= geo.getFromLocationName("Tesco",1); Address yourAddress = // get your location or the address to compare Address closest = findClosest(addressList, yourAddress); // do what you need }
Geocoder geocoder = new Geocoder(context, Locale.getDefault()); String result = null; try { List<Address> addressList = geocoder.getFromLocation( latitude, longitude, 1); if (addressList != null && addressList.size() > 0) { Address address = addressList.get(0); StringBuilder sb = new StringBuilder(); for (int i = 0; i < address.getMaxAddressLineIndex(); i++) { sb.append(address.getAddressLine(i)).append("\n"); } sb.append(address.getLocality()).append("\n"); sb.append(address.getPostalCode()).append("\n"); sb.append(address.getCountryName()); result = sb.toString(); } } catch (IOException e) { Log.e(TAG, "Unable connect to Geocoder", e); }
Geocoder gc = new Geocoder(ctx, Locale.getDefault()); List<Address> addresses; addresses = gc.getFromLocation(lat, lng, 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(","); }
Geocoder myLocation = new Geocoder(yourContext, Locale.getDefault()); List<Address> myList = myLocation.getFromLocation(Double.parseDouble(latitude),Double.parseDouble(longitude), 1); Address address = (Address) myList.get(0); String addressStr = ""; addressStr += address.getAddressLine(0) + ", "; addressStr += address.getAddressLine(1) + ", "; addressStr += address.getAddressLine(2);
try { if (theFrag.diaryLocations != null) { List<String> providerList = theFrag.locationManager.getAllProviders(); if (null != theFrag.diaryLocations && null != providerList && providerList.size() > 0) { double longitude = theFrag.diaryLocations.getLongitude(); double latitude = theFrag.diaryLocations.getLatitude(); Geocoder geocoder = new Geocoder(theFrag.getActivity().getApplicationContext(), Locale.getDefault()); List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1); if (null != listAddresses && listAddresses.size() > 0) { try { theFrag.diaryLocations = null; try { theFrag.locationManager.removeUpdates(theFrag.locationListener); } catch (SecurityException e) { e.printStackTrace();
public static Address retrieveAddress(Context context, double lat, double lng) { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); try { List<Address> addresses = geocoder.getFromLocation(lat, lng, 1); if (addresses.size() > 0) { return addresses.get(0); } } catch (IOException | IllegalArgumentException e) { e.printStackTrace(); } return null; }
Thread thread = new Thread() { @Override public void run() { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); String result = null; try { List<Address> list = geocoder.getFromLocation( location.getLatitude(), location.getLongitude(), 1); if (list != null && list.size() > 0) { Address address = list.get(0); result = address.getAddressLine(0) + ", " + address.getLocality();
public String getAddress(Context ctx, double latitude, double longitude) { StringBuilder result = new StringBuilder(); try { Geocoder geocoder = new Geocoder(ctx, Locale.getDefault()); List<address> addresses = geocoder.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) { Address address = addresses.get(0); String locality=address.getLocality(); String city=address.getCountryName(); String region_code=address.getCountryCode(); String zipcode=address.getPostalCode(); double lat =address.getLatitude(); double lon= address.getLongitude(); result.append(locality+" "); result.append(city+" "+ region_code+" "); result.append(zipcode); } } catch (IOException e) { Log.e("tag", e.getMessage()); } return result.toString(); }
GeocoderGoogle(@AppContext Context context){ geocoder = new android.location.Geocoder(context, Locale.getDefault()); } }
Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); String provider = locationManager.getBestProvider(criteria,true); Location curLocation = locationManager.getLastKnownLocation(provider); GeoPoint curGeoPoint = new GeoPoint((int)(curLocation.getLatitude() * 1e6), (int)(curLocation.getLongitude()*1e6)); return curGeoPoint; } catch (NullPointerException e) { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); List<Address> addresses = null; try { addresses = geocoder.getFromLocation((double)curLocal.getLatitudeE6() / 1e6,(double)curLocal.getLongitudeE6()/ 1e6,1); } catch (IOException ignored) { Address result;
Location location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null) { location = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Geocoder gcd = new Geocoder(context, Locale.getDefault()); List<Address> addresses; try { addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (!Geocoder.isPresent()) { Log.e(TAG, "No Geocoder Available"); return returnString; } else { Geocoder gc = new Geocoder(this, Locale.getDefault()); try { List<Address> addresses = gc.getFromLocation(location.getLatitude(), location.getLongitude(), 1); // One Result
@Override public List<Address> loadInBackground() { Geocoder geocoder = new Geocoder(mContext, Locale.getDefault()); try { mEnderecosEncontrados = geocoder.getFromLocationName(mLocal, 10); } catch (Exception e) { e.printStackTrace(); } return mEnderecosEncontrados; } }