Android 路径查询具体实现
程序员文章站
2023-11-22 00:02:34
返回结果存放在mapdirection中,mapdirection包含了路径的详细信息,包括路径的每个步骤,长度,时间,方向等。java代码:复制代码 代码如下:packa...
返回结果存放在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){
}
}
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){
}
}