Android path Query

Source: Internet
Author: User

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 ){

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.