Activity tempActivity = App.getMultiRoundActivity(); if (tempActivity != null && tempActivity instanceof MapBaseActivity) { ((MapBaseActivity) tempActivity).searchPoiWithLocationCheck(pi); }这个调用方法是, public void searchPoiWithLocationCheck(PoiSearchInfo poiSearchInfo) { this.mPoiSearchInfo = poiSearchInfo; Log.i(getClass().getSimpleName(), "searchPoiWithLocationCheck: "); mHandler.post(() -> { if (location_last_success_time == 0 || (System.currentTimeMillis() - location_last_success_time) > LOCATION_MAX_USE_TIME) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck , wait for location ready" + mLocClient); if (mToastLocating == null) { mToastLocating = Toast.makeText(MapBaseActivity.this, "正在定位,请稍后", Toast.LENGTH_LONG); } if (mLocClient == null) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck : reInit location caused by null"); initLocation(); } else if (!mLocClient.isStarted()) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck : restart location caused by stoped"); mLocClient.start(); } mIsPoiSearchNeeded = true; mToastLocating.show(); } else { searchPoi(poiSearchInfo); } }); 其中,会走else,也就是searchPoi(poiSearchInfo);方法, public void searchPoi(PoiSearchInfo poiSearchInfo) { Log.i(getClass().getSimpleName(), "searchPoi: " + poiSearchInfo ); mIsPoiSearchNeeded = false; // 配置请求参数 附近检索 if (poiSearchInfo.getSearchType() == Constant.MAP_SEARCH_CITY){ searchInCity(poiSearchInfo); } else { searchNearBy(poiSearchInfo); } } 帮我修改一下这个调用方法的时候,要区分是哪一个行动,也就是去修改去目的地还是添加途经点
时间: 2024-02-04 15:03:32 浏览: 74
根据您提供的代码,我看不出这个方法是用来修改目的地还是添加途经点的。不过,可以通过修改 `PoiSearchInfo` 对象的某些属性来区分是修改目的地还是添加途经点。具体来说,您可以添加一个 `boolean` 类型的属性来表示是否为目的地,然后在调用 `searchPoiWithLocationCheck` 方法时,根据这个属性来决定是调用修改目的地的方法还是添加途经点的方法。例如:
```
public void searchPoiWithLocationCheck(PoiSearchInfo poiSearchInfo) {
this.mPoiSearchInfo = poiSearchInfo;
Log.i(getClass().getSimpleName(), "searchPoiWithLocationCheck: ");
mHandler.post(() -> {
if (location_last_success_time == 0 || (System.currentTimeMillis() - location_last_success_time) > LOCATION_MAX_USE_TIME) {
Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck , wait for location ready" + mLocClient);
if (mToastLocating == null) {
mToastLocating = Toast.makeText(MapBaseActivity.this, "正在定位,请稍后", Toast.LENGTH_LONG);
}
if (mLocClient == null) {
Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck : reInit location caused by null");
initLocation();
} else if (!mLocClient.isStarted()) {
Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck : restart location caused by stoped");
mLocClient.start();
}
mIsPoiSearchNeeded = true;
mToastLocating.show();
} else {
if (poiSearchInfo.isDestination()) {
modifyDestination(poiSearchInfo);
} else {
addWaypoint(poiSearchInfo);
}
}
});
}
```
其中,`PoiSearchInfo` 对象可以定义为如下所示:
```
public class PoiSearchInfo {
private boolean isDestination; // 是否为目的地
private int searchType; // 搜索类型
// 其他属性
// 构造方法
// Getter 和 Setter
}
```
这样,就可以通过 `isDestination` 属性来区分不同的行为。对应的修改目的地和添加途经点的方法可以根据实际需求自行编写。
阅读全文