Android Path Query

Source: Internet
Author: User

You can query the path through the Rastermap getdirection () method, similar to the query address, and the result of the path query is to notify the application by way of a callback function, the following example returns to the path of Nanjing to Beijing. The return result is stored in mapdirection, Mapdirection contains the details of the path, including each step of the path, length, time, direction, and so on.

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

}

}

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.