Hi!
I'm trying to use Geocoder.getFromLocationName() with a bounding box,
but:
* On 1.5 I get lots of results outside of my box.
* On 1.6 I get no results at all.
How should I use Geocoder.getFromLocationName() with a bounding box so
that I get results inside of the box but not outside of it?
Here's what I'm trying to do. The example address "Storgatan 5" is
very common in Sweden and exists in lots of cities, so it's a good
test case. The bounding box covers the Stockholm area:
/**
* Try to find Storgatan 5 in Stockholm using {...@link
Geocoder#getFromLocationName(String, int, double, double, double,
double)}.
* <p>
* On 1.5, this example finds tons of "Storgatan 5"s, none of them
inside the
* box unfortunately.
* <p>
* On 1.6 I get no results at all from this code.
*
* @author [email protected]
*/
public class FindStorgatan extends Activity {
/**
* Use this tag for logging.
*/
public final static String TAG = "Storgatan";
/**
* Lower left latitude of SL's coverage.
*/
private static final double SL_LOWER_LEFT_LAT = 58.9693;
/**
* Lower left longitude of SL's coverage.
*/
private static final double SL_LOWER_LEFT_LON = 17.1754;
/**
* Upper right latitude of SL's coverage.
*/
private static final double SL_UPPER_RIGHT_LAT = 59.8307;
/**
* Upper right longitude of SL's coverage.
*/
private static final double SL_UPPER_RIGHT_LON = 19.1907;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up our Geocoder
Locale swedish = new Locale("sv");
Geocoder geocoder = new Geocoder(this, swedish);
// "Storgatan 5" is a common address in many Swedish cities
String findMe = "Storgatan 5";
List<Address> locations;
try {
locations =
geocoder.getFromLocationName(findMe, 7,
SL_LOWER_LEFT_LAT,
SL_LOWER_LEFT_LON,
SL_UPPER_RIGHT_LAT,
SL_UPPER_RIGHT_LON);
} catch (IOException e) {
Log.e(TAG, "Address decoding failed for: " + findMe, e);
return;
}
StringBuilder result = new StringBuilder();
result.append(locations.size());
result.append(" results found for ");
result.append(findMe);
result.append(":\n");
for (Address address : locations) {
String addressLine = address.getAddressLine(0);
String city = address.getAddressLine(1);
String lat = Double.toString(address.getLatitude());
String lon = Double.toString(address.getLongitude());
String coordinate = lat + ", " + lon;
if (!findMe.equals(addressLine)) {
result.append(addressLine).append(", ");
}
result.append(city).append(": ").append(coordinate).append
('\n');
}
// Display our result
TextView textView = new TextView(this);
textView.setText(result);
setContentView(textView);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---