Android 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 com. pstreets. gisengine. demo;

Import com. mapdigit. gis. MapDirection;
Import com. mapdigit. gis. MapPoint;
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. mapdigit. gis. service. IRoutingListener;
Import com. pstreets. gisengine. R;
Import com. pstreets. gisengine. SharedMapInstance;

Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. Menu;
Import android. view. MenuInflater;
Import android. view. MenuItem;

Public class MapRouting extends Activity implements IRoutingListener {

@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
}

@ Override
Public void onStart (){
Super. onStart ();
GeoLatLng center = new GeoLatLng (32.0616667, 118.7777778 );
SharedMapInstance. map. setCenter (center, 15,
Com. mapdigit. gis. raster. MapType. MICROSOFTCHINA );
SharedMapInstance. map. setRoutingListener (this );

}

@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
MenuInflater inflater = getMenuInflater ();
Inflater. inflate (R. menu. maprouting_menu, menu );
Return true;
}

@ Override
Public boolean onOptionsItemSelected (MenuItem item ){
// Handle item selection
Switch (item. getItemId ()){
Case R. id. getdirection:
String name1 = "Nanjing ";
String name2 = "Beijing ";
SharedMapInstance. map. getDirections ("from:" + name1 + ":"
+ Name2 );

Return true;

Default:
Return super. onOptionsItemSelected (item );
}

}

@ Override
Public void done (String query, MapDirection result ){
If (result! = Null ){
SharedMapInstance. map. setMapDirection (result );
SharedMapInstance. map. resize (result. getBound ());
SharedMapInstance. map. zoomOut ();
SharedMapInstance. map. zoomOut ();

}

}

@ Override
Public void readProgress (int bytes, int total ){

}

}
Package com. pstreets. gisengine. demo;
 
Import com. mapdigit. gis. MapDirection;
Import com. mapdigit. gis. MapPoint;
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. mapdigit. gis. service. IRoutingListener;
Import com. pstreets. gisengine. R;
Import com. pstreets. gisengine. SharedMapInstance;
 
Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. Menu;
Import android. view. MenuInflater;
Import android. view. MenuItem;
 
Public class MapRouting extends Activity implements IRoutingListener {
 
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
}
 
@ Override
Public void onStart (){
Super. onStart ();
GeoLatLng center = new GeoLatLng (32.0616667, 118.7777778 );
SharedMapInstance. map. setCenter (center, 15,
Com. mapdigit. gis. raster. MapType. MICROSOFTCHINA );
SharedMapInstance. map. setRoutingListener (this );
 
}
 
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
MenuInflater inflater = getMenuInflater ();
Inflater. inflate (R. menu. maprouting_menu, menu );
Return true;
}
 
@ Override
Public boolean onOptionsItemSelected (MenuItem item ){
// Handle item selection
Switch (item. getItemId ()){
Case R. id. getdirection:
String name1 = "Nanjing ";
String name2 = "Beijing ";
SharedMapInstance. map. getDirections ("from:" + name1 + ":"
+ Name2 );
 
Return true;
 
Default:
Return super. onOptionsItemSelected (item );
}
 
}
 
@ Override
Public void done (String query, MapDirection result ){
If (result! = Null ){
SharedMapInstance. map. setMapDirection (result );
SharedMapInstance. map. resize (result. getBound ());
SharedMapInstance. map. zoomOut ();
SharedMapInstance. map. zoomOut ();
 
}
 
}
 
@ Override
Public void readProgress (int bytes, int total ){
 
}
 
}


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 listener );

Author: mapdigit
 

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.