You can use the getDirection () method of RasterMap to query the path. Similar to the query address, the path query result notifies the application through the callback function, the following example returns the path from Nanjing to Beijing. The returned results are stored in MapDirection. MapDirection contains detailed information about the path, including each step, length, time, and direction of the path.
Java code:
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 = "Nanjing ";
Stringname2 = "Beijing ";
SharedMapInstance. map. getDirections ("from:" + name1 + ":"
+ 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 ){
}
}