Android 在osmdroid中搜索位置时出错
嗨,当我试图在开放的街道地图上搜索位置时,我发现地理编码错误。请帮助我。我正在使用osm奖金包,但我也得到了错误。 当我按下搜索按钮时,它会在捕获块中显示异常,所以请帮助我的朋友Android 在osmdroid中搜索位置时出错,android,openstreetmap,osmdroid,Android,Openstreetmap,Osmdroid,嗨,当我试图在开放的街道地图上搜索位置时,我发现地理编码错误。请帮助我。我正在使用osm奖金包,但我也得到了错误。 当我按下搜索按钮时,它会在捕获块中显示异常,所以请帮助我的朋友 public void handleSearchButton(int index, int editResId){ EditText locationEdit = (EditText)findViewById(editResId); //Hide the soft keyboard:
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();
}
}
public void handleSearchButton(int-index,int-editResId){
EditText位置Edit=(EditText)findViewById(editResId);
//隐藏软键盘:
InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT\u方法\u服务);
imm.hideSoftInputFromWindow(locationEdit.getWindowToken(),0);
String locationAddress=locationEdit.getText().toString();
if(locationAddress.equals(“”){
移除点(索引);
map.invalidate();
返回;
}
Toast.makeText(这是“搜索:\n”+位置地址,Toast.LENGTH_LONG).show();
AutoCompleteOnPreferences.StorePreferences(此项、locationAddress、SHARED\u PREFS\u APPKEY、PREF\u LOCATIONS\u KEY);
GeocoderNominatim geocoder=新的GeocoderNominatim(本);
geocoder.setOptions(true);//询问封闭多边形(如果有)
试一试{
List FoundAddress=geocoder.getFromLocationName(locationAddress,1);
如果(foundAddresses.size()==0){//如果找不到地址,则显示错误
Toast.makeText(这是“找不到地址”,Toast.LENGTH_SHORT).show();
}否则{
地址地址=foundAddresses.get(0);//获取第一个地址
如果(索引==开始索引){
startPoint=新的地理点(address.getLatitude(),address.getLatitude());
markerStart=putMarkerItem(markerStart、startPoint、START\u索引、,
R.string.出发,R.drawable.marker_出发,-1);
map.getController().setCenter(startPoint);
}else if(index==DEST_index){
destinationPoint=新的地理点(address.getLatitude(),address.getLatitude());
markerDestination=putMarkerItem(markerDestination、destinationPoint、DEST_索引、,
R.string.destination,R.drawable.marker_destination,-1);
map.getController().setCenter(destinationPoint);
}
getRoadAsync();
//获取并显示封闭多边形:
Bundle extras=address.getExtras();
if(extras!=null&&extras.containsKey(“polygonpoints”)){
ArrayList polygon=extras.getParcelableArrayList(“多边形点”);
//Log.d(“调试”,“多边形:+polygon.size());
更新多边形(多边形);
}否则{
updateUIWithPolygon(空);
}
}
}捕获(例外e){
Toast.makeText(这是“地理编码错误”,Toast.LENGTH_SHORT).show();
}
}
请发布相关异常,并告诉我们它发生在哪个代码行。当搜索目标地址时,它执行的是try块,执行catch blocking并在catch块中显示地理编码错误。请通过打印e.getMessage()
准确显示您的异常。没有这些信息,就不可能知道出了什么问题。