Java ME guide bee map development example: 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]
// ----------------------------------- PACKAGE ------------------------------------
Package com. pstreets. gisengine. demo. midp;


// ------------------------------------- IMPORTS ------------------------------------
Import com. mapdigit. gis. MapDirection;
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. mapdigit. gis. raster. MapType;
Import com. mapdigit. gis. service. IRoutingListener;
Import com. pstreets. gisengine. demo. MapDemoMIDP;
Import javax. microedition. lcdui. Command;
Import javax. microedition. lcdui. CommandListener;
Import javax. microedition. lcdui. Display;
Import javax. microedition. lcdui. Displayable;


// [-------------------------------- Main class ----------------------------------]
// ----------------------------------- REVISIONS ----------------------------------
// Date Name Tracking # Description
//------------------------------------------------------------------
// 28JAN2011 James Shen Initial Creation
//////////////////////////////////////// ////////////////////////////////////////
/**
* Map routing demo for Guidebee Map API on MIDP platform.
*/
Public class MapRoutingMIDP extends MapDemoMIDP implements CommandListener,
IRoutingListener {


Private Command mapgetdirecommand Command = new Command ("Get Direction ",
Command. OK, 1 );


Public void startApp (){


Init ();
Canvas. addCommand (mapgetdirecommand command );
Map. setRoutingListener (this );
Canvas. setCommandListener (this );
GeoLatLng center = new GeoLatLng (-31.948275, 115.857562 );
Map. setCenter (center, 13, MapType. GOOGLEMAP );


Display. getDisplay (this). setCurrent (canvas );
}


Public void commandAction (Command c, Displayable d ){
If (c = mapgetdirecommand command ){
String name1 = "?? ";
String name2 = "?? ";
Map. getDirections ("from:" + name1 + "to:" + name2 );


}
}


Public void done (String query, MapDirection result ){
If (result! = Null ){
Map. setMapDirection (result );
Map. resize (result. getBound ());
Map. setZoom (3 );


}
}
}
// ----------------------------------- PACKAGE ------------------------------------
Package com. pstreets. gisengine. demo. midp;
 
 
// ------------------------------------- IMPORTS ------------------------------------
Import com. mapdigit. gis. MapDirection;
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. mapdigit. gis. raster. MapType;
Import com. mapdigit. gis. service. IRoutingListener;
Import com. pstreets. gisengine. demo. MapDemoMIDP;
Import javax. microedition. lcdui. Command;
Import javax. microedition. lcdui. CommandListener;
Import javax. microedition. lcdui. Display;
Import javax. microedition. lcdui. Displayable;
 
 
// [-------------------------------- Main class ----------------------------------]
// ----------------------------------- REVISIONS ----------------------------------
// Date Name Tracking # Description
//------------------------------------------------------------------
// 28JAN2011 James Shen Initial Creation
//////////////////////////////////////// ////////////////////////////////////////
/**
* Map routing demo for Guidebee Map API on MIDP platform.
*/
Public class MapRoutingMIDP extends MapDemoMIDP implements CommandListener,
IRoutingListener {
 
 
Private Command mapgetdirecommand Command = new Command ("Get Direction ",
Command. OK, 1 );
 
 
Public void startApp (){
 
 
Init ();
Canvas. addCommand (mapgetdirecommand command );
Map. setRoutingListener (this );
Canvas. setCommandListener (this );
GeoLatLng center = new GeoLatLng (-31.948275, 115.857562 );
Map. setCenter (center, 13, MapType. GOOGLEMAP );
 
 
Display. getDisplay (this). setCurrent (canvas );
}
 
 
Public void commandAction (Command c, Displayable d ){
If (c = mapgetdirecommand command ){
String name1 = "?? ";
String name2 = "?? ";
Map. getDirections ("from:" + name1 + "to:" + name2 );
 
 
}
}
 
 
Public void done (String query, MapDirection result ){
If (result! = Null ){
Map. setMapDirection (result );
Map. resize (result. getBound ());
Map. setZoom (3 );
 
 
}
}
}

 

You can use the Google map service and CloudMade map service. You may also choose the MapAbc map service in China. The Google map service is used by default.
GetDirections () has three overload functions. In this example, the text description is used. The preceding example uses the from: address1 to: address2 format. The CloudMade and MapAbc map services must adopt the longitude 1, latitude 1, longitude 2, latitude 2 and format.
To avoid confusion, you can use the following format.
Public void getDirection (GeoLatLng [] waypoints, IRoutingListener listener );
Waypoints is the latitude and longitude value of the path coordinate array, and supports multi-point path query.
In addition, for the MapAbc map service, you can also specify the city code, for example, Nanjing code is 25.
Public void getDirection (int citycode, String query, IRoutingListener

Author: mapdigit
 

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.