Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Fix #396 - Improvement of android geocoder workarounds. #408

Merged
merged 2 commits into from
Sep 4, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

Expand Down Expand Up @@ -186,17 +187,24 @@ public static ArrayList<CustomAddress> processGeocoding(Context context, Server
Geocoder gc = new Geocoder(context);
try {
List<Address> androidTypeAddresses;
if (selectedServer != null) {
//Temporary workaround while Google does not solve the problem with Android Geocoder, see issue #396
//TODO Temporary workaround while Google does not solve the problem with Android Geocoder, see issue #396
/*if (selectedServer != null) {
androidTypeAddresses = gc.getFromLocationName(address,
context.getResources().getInteger(R.integer.geocoder_max_results)/*,
context.getResources().getInteger(R.integer.geocoder_max_results),
selectedServer.getLowerLeftLatitude(),
selectedServer.getLowerLeftLongitude(),
selectedServer.getUpperRightLatitude(),
selectedServer.getUpperRightLongitude()*/);
selectedServer.getUpperRightLongitude());
} else {
androidTypeAddresses = gc.getFromLocationName(address,
context.getResources().getInteger(R.integer.geocoder_max_results));
}*/
if (geocodingForMarker){
androidTypeAddresses = gc.getFromLocationName(address,
context.getResources().getInteger(R.integer.geocoder_max_results));
}
else{
androidTypeAddresses = new ArrayList<Address>();
}
for (Address androidTypeAddress : androidTypeAddresses){
addresses.add(new CustomAddress(androidTypeAddress));
Expand Down Expand Up @@ -276,17 +284,14 @@ public static ArrayList<CustomAddress> processGeocoding(Context context, Server
*/
private static List<CustomAddress> filterAddressesBBox(Server selectedServer, List<CustomAddress> addresses) {
if ((!(addresses == null || addresses.isEmpty())) && selectedServer != null) {
CopyOnWriteArrayList<CustomAddress> addressesFiltered = new CopyOnWriteArrayList<CustomAddress>(addresses);

for (CustomAddress address : addressesFiltered) {
for (Iterator<CustomAddress> it=addresses.iterator(); it.hasNext();) {
CustomAddress address = it.next();
if (!LocationUtil.checkPointInBoundingBox(
new LatLng(address.getLatitude(), address.getLongitude()), selectedServer,
OTPApp.CHECK_BOUNDS_ACCEPTABLE_ERROR)) {
addressesFiltered.remove(address);
it.remove();
}
}

return addressesFiltered;
}
return addresses;
}
Expand Down