@Before public void setUp() throws Exception { Context context = ApplicationProvider.getApplicationContext(); geocoder = new Geocoder(context); }
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) {
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) {
public AddressGeocoder(Context context) { this.geocoder = new Geocoder(context); }
private void listing15_20() { // Listing 15-20: Geocoding an address Geocoder geocoder = new Geocoder(this, Locale.US); String streetAddress = "160 Riverside Drive, New York, New York"; List<Address> locations = null; try { locations = geocoder.getFromLocationName(streetAddress, 5); } catch (IOException e) { Log.e(TAG, "Geocoder I/O Exception", e); } } }
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; }
public ReverseGeocoder(Context context) { mContext = context; mGeocoder = new Geocoder(mContext); mGeoCache = CacheManager.getCache(context, GEO_CACHE_FILE, GEO_CACHE_MAX_ENTRIES, GEO_CACHE_MAX_BYTES, GEO_CACHE_VERSION); mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); }
private void reverseGeocode(Location location) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); List<Address> addresses = null; Geocoder gc = new Geocoder(this, Locale.getDefault()); try { addresses = gc.getFromLocation(latitude, longitude, 10); } catch (IOException e) { Log.e(TAG, "Geocoder I/O Exception", e); } }
@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; } }
@Provides ReverseGeocoder reverseGeocoder(Application application) { Geocoder geocoder = new Geocoder(application, Locale.getDefault()); return new StandardReverseGeocoder(geocoder); }
GeocoderGoogle(@AppContext Context context){ geocoder = new android.location.Geocoder(context, Locale.getDefault()); } }
public Address getAddressFromLocation(final double latitude, final double longitude, final Context context) { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); try { List<Address> addressList = geocoder.getFromLocation( latitude, longitude, 1); if (addressList != null && addressList.size() > 0) { address = addressList.get(0); } } catch (IOException e) { Log.e(TAG, "Unable connect to Geocoder", e); } return address; }
public void run() { try { Geocoder gc = new Geocoder(getBaseContext(), new Locale("pt", "BR")); List<Address> list = gc.getFromLocationName("Av Paulista - SP", 10); toast("addresses: " + list); } catch (IOException e) { toast("Erro: " + e.getMessage()); } } }.start();
public static void init(Context cntxt) { Log.d(LOG_TAG, "Initializing Location"); context = cntxt; if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED ) { // Impossible to call requestPermissions from a service. It has to be done from an activity => stop the service context.sendBroadcast(new Intent(OpenFitIntent.INTENT_SERVICE_STOP)); } else { // Permission has already been granted locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); geocoder = new Geocoder(context, Locale.getDefault()); updateLastKnownLocation(); listenForLocation(true); } }
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); } }
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); } }
@Override protected List<Address> doInBackground(String... locationName) { // Creating an instance of Geocoder class Geocoder geocoder = new Geocoder(getBaseContext()); List<Address> addresses = null; try { // Getting a maximum of 3 Address that matches the input text addresses = geocoder.getFromLocationName(locationName[0], 1); } catch (IOException e) { e.printStackTrace(); } return addresses; }
@Override protected Address doInBackground(final String... locationName) { // Creating an instance of Geocoder class Geocoder geocoder = new Geocoder(map.getBaseContext()); try { // Get only the best result that matches the input text List<Address> addresses = geocoder.getFromLocationName(locationName[0], 1); return addresses != null && !addresses.isEmpty() ? addresses.get(0) : null; } catch (IOException e) { if (BuildConfig.DEBUG) Logger.log(e); e.printStackTrace(); return null; } }
public LocationProvider(Context context) { mLocationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); mGeocoder = new Geocoder(context); final Criteria criteria = new Criteria(); mBestProvider = mLocationManager.getBestProvider(criteria, true); final List<String> providers = mLocationManager.getProviders( criteria, true); for (String provider : providers) { // mLocationManager.requestLocationUpdates(provider, 0, 0, this); } }