嗨,当我试图在开放街道地图上搜索位置时,我收到地理编码错误。请帮助我。我正在使用osm奖励包,但我也得到错误。 当我按下搜索按钮时,它会在catch块中显示异常,所以请帮助我的朋友。
public void handleSearchButton(int index, int editResId){
EditText locationEdit = (EditText)findViewById(editResId);
//Hide the soft keyboard:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(locationEdit.getWindowToken(), 0);
String locationAddress = locationEdit.getText().toString();
if (locationAddress.equals("")){
removePoint(index);
map.invalidate();
return;
}
Toast.makeText(this, "Searching:\n"+locationAddress, Toast.LENGTH_LONG).show();
AutoCompleteOnPreferences.storePreference(this, locationAddress, SHARED_PREFS_APPKEY, PREF_LOCATIONS_KEY);
GeocoderNominatim geocoder = new GeocoderNominatim(this);
geocoder.setOptions(true); //ask for enclosing polygon (if any)
try {
List<Address> foundAdresses = geocoder.getFromLocationName(locationAddress, 1);
if (foundAdresses.size() == 0) { //if no address found, display an error
Toast.makeText(this, "Address not found.", Toast.LENGTH_SHORT).show();
} else {
Address address = foundAdresses.get(0); //get first address
if (index == START_INDEX){
startPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
markerStart = putMarkerItem(markerStart, startPoint, START_INDEX,
R.string.departure, R.drawable.marker_departure, -1);
map.getController().setCenter(startPoint);
} else if (index == DEST_INDEX){
destinationPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
markerDestination = putMarkerItem(markerDestination, destinationPoint, DEST_INDEX,
R.string.destination, R.drawable.marker_destination, -1);
map.getController().setCenter(destinationPoint);
}
getRoadAsync();
//get and display enclosing polygon:
Bundle extras = address.getExtras();
if (extras != null && extras.containsKey("polygonpoints")){
ArrayList<GeoPoint> polygon = extras.getParcelableArrayList("polygonpoints");
//Log.d("DEBUG", "polygon:"+polygon.size());
updateUIWithPolygon(polygon);
} else {
updateUIWithPolygon(null);
}
}
} catch (Exception e) {
Toast.makeText(this, "Geocoding error", Toast.LENGTH_SHORT).show();
}
}