Android 路径查询具体实现

时间:2021-05-21

返回结果存放在MapDirection中,MapDirection包含了路径的详细信息,包括路径的每个步骤,长度,时间,方向等。
Java代码:
复制代码 代码如下:
packageeoe.demo;
importcom.mapdigit.gis.MapDirection;
importcom.mapdigit.gis.MapPoint;
importcom.mapdigit.gis.geometry.GeoLatLng;
importcom.mapdigit.gis.service.IRoutingListener;
importcom.pstreets.gisengine.R;
importcom.pstreets.gisengine.SharedMapInstance;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Menu;
importandroid.view.MenuInflater;
importandroid.view.MenuItem;
publicclassMapRoutingextendsActivityimplementsIRoutingListener{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
publicvoidonStart(){
super.onStart();
GeoLatLngcenter=newGeoLatLng(32.0616667,118.7777778);
SharedMapInstance.map.setCenter(center,15,
com.mapdigit.gis.raster.MapType.MICROSOFTCHINA);
SharedMapInstance.map.setRoutingListener(this);
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
MenuInflaterinflater=getMenuInflater();
inflater.inflate(R.menu.maprouting_menu,menu);
returntrue;
}
@Override
publicbooleanonOptionsItemSelected(MenuItemitem){
//Handleitemselection
switch(item.getItemId()){
caseR.id.getdirection:
Stringname1="南京";
Stringname2="北京";
SharedMapInstance.map.getDirections("from:"+name1+"to:"
+name2);
returntrue;
default:
returnsuper.onOptionsItemSelected(item);
}
}
@Override
publicvoiddone(Stringquery,MapDirectionresult){
if(result!=null){
SharedMapInstance.map.setMapDirection(result);
SharedMapInstance.map.resize(result.getBound());
SharedMapInstance.map.zoomOut();
SharedMapInstance.map.zoomOut();
}
}
@Override
publicvoidreadProgress(intbytes,inttotal){
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章