android百度地图3.1中在onGetBusLineResult,要怎么打印出当前查询公交的每一站的信息呢
1个回答
2015-03-10
展开全部
1、首先需要得到公交路线的UID:用PoiSearch搜索公交路线,然后在得到的结果中处理。由于公交路线都是双向的,而且比如搜索m123,可能得到的类型不止是公交,还可能是其他含有这个关键字的结果,所以这里需要你进行判断筛选。
2、找到了UID,就可以通过BusLineSearch来搜索指定线路的公交站台,
参考如下代码,搜索了深圳市m345路公交(公交都是双向,这里我选了第一项)
import java.util.List;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.search.busline.BusLineResult;
import com.baidu.mapapi.search.busline.BusLineResult.BusStation;
import com.baidu.mapapi.search.busline.BusLineSearch;
import com.baidu.mapapi.search.busline.BusLineSearchOption;
import com.baidu.mapapi.search.busline.OnGetBusLineSearchResultListener;
import com.baidu.mapapi.search.core.PoiInfo;
import com.baidu.mapapi.search.core.PoiInfo.POITYPE;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiCitySearchOption;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiResult;
import com.baidu.mapapi.search.poi.PoiSearch;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
MapView mMapView = null;
Button btn=null;
PoiSearch mPoiSearch;
BusLineSearch mBusSearch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
mMapView=(MapView)findViewById(R.id.bmapView);
btn=(Button)findViewById(R.id.button);
mBusSearch=BusLineSearch.newInstance();
mBusSearch.setOnGetBusLineSearchResultListener(new OnGetBusLineSearchResultListener() {
@Override
public void onGetBusLineResult(BusLineResult result) {
System.out.println("----------------");
System.out.println("公交公司:"+result.getBusCompany());
System.out.println("公交线路名称:"+result.getBusLineName());
System.out.println("----------------");
List<BusStation> list=result.getStations();
if(list==null||list.isEmpty())
return;
for(BusStation station:list)
{
System.out.println(station.getTitle());
}
}
});
mPoiSearch=PoiSearch.newInstance();
mPoiSearch.setOnGetPoiSearchResultListener(new OnGetPoiSearchResultListener() {
@Override
public void onGetPoiResult(PoiResult searchResult) {
if(searchResult==null)
return;
List<PoiInfo> list=searchResult.getAllPoi();
if(list==null||list.isEmpty())
return;
for(int i=0;i<list.size();i++)
{
if(list.get(i).type==POITYPE.BUS_LINE){
mBusSearch.searchBusLine((new BusLineSearchOption()).city("深圳")
.uid(list.get(i).uid));
break;
}
}
}
@Override
public void onGetPoiDetailResult(PoiDetailResult result) {
}
});
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mPoiSearch.searchInCity((new PoiCitySearchOption()).
city("深圳").keyword("m345"));
}
});
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询