List of usage examples for android.location Geocoder getFromLocationName
public List<Address> getFromLocationName(String locationName, int maxResults, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude) throws IOException
From source file:edu.usf.cutr.opentripplanner.android.tasks.OTPGeocoding.java
protected Long doInBackground(String... reqs) { long count = reqs.length; String address = reqs[0];//from www . ja va 2s . co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (address == null || address.equalsIgnoreCase("")) { return count; } if (address.equalsIgnoreCase(context.getString(R.string.my_location))) { String currentLat = reqs[1]; String currentLng = reqs[2]; LatLng latLng = new LatLng(Double.parseDouble(currentLat), Double.parseDouble(currentLng)); Address addressReturn = new Address(context.getResources().getConfiguration().locale); addressReturn.setLatitude(latLng.latitude); addressReturn.setLongitude(latLng.longitude); addressReturn.setAddressLine(addressReturn.getMaxAddressLineIndex() + 1, context.getString(R.string.my_location)); addressesReturn.add(addressReturn); return count; } ArrayList<Address> addresses = null; if (prefs.getBoolean(OTPApp.PREFERENCE_KEY_USE_ANDROID_GEOCODER, true)) { Log.d("test", "create a geocoder"); Geocoder gc = new Geocoder(context); try { if (selectedServer != null) { addresses = (ArrayList<Address>) gc.getFromLocationName(address, context.getResources().getInteger(R.integer.geocoder_max_results), selectedServer.getLowerLeftLatitude(), selectedServer.getLowerLeftLongitude(), selectedServer.getUpperRightLatitude(), selectedServer.getUpperRightLongitude()); } else { addresses = (ArrayList<Address>) gc.getFromLocationName(address, context.getResources().getInteger(R.integer.geocoder_max_results)); } } catch (IOException e) { e.printStackTrace(); } } addresses = filterAddressesBBox(addresses); if ((addresses == null) || addresses.isEmpty()) { addresses = searchPlaces(address); for (int i = 0; i < addresses.size(); i++) { Address addr = addresses.get(i); String str = addr.getAddressLine(0); List<String> addrLines = Arrays.asList(str.split(", ")); for (int j = 0; j < addrLines.size(); j++) { addr.setAddressLine(j, addrLines.get(j)); } } } addresses = filterAddressesBBox(addresses); addressesReturn.addAll(addresses); return count; }