Let's take a look at the effect chart:
1, just enter the time:, the default for Beijing
2, click the "Bus" button:
3, click the "Car" button:
4, click the "Walk" button
All right, let's get this done!
layout : <?xml version= "1.0″encoding=" utf-8″?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content" >
Android:id= "@+id/btn_bus"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
Android:layout_weight= "1″
android:onclick= "DoClick"
Android:id= "@+id/btn_car"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
Android:layout_weight= "1″
android:onclick= "DoClick"
Android:id= "@+id/btn_walk"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
Android:layout_weight= "1″
android:onclick= "DoClick"
<com.amap.api.maps.mapview
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" ></com.amap.api.maps.MapView>
Package cn.zmit.xianneng.activity;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Com.amap.api.maps.AMap;
Import Com.amap.api.maps.MapView;
Import Com.amap.api.maps.overlay.BusRouteOverlay;
Import Com.amap.api.maps.overlay.DrivingRouteOverlay;
Import Com.amap.api.maps.overlay.WalkRouteOverlay;
Import Com.amap.api.services.core.LatLonPoint;
Import Com.amap.api.services.route.BusPath;
Import Com.amap.api.services.route.BusRouteResult;
Import Com.amap.api.services.route.DrivePath;
Import Com.amap.api.services.route.DriveRouteResult;
Import Com.amap.api.services.route.RouteSearch;
Import Com.amap.api.services.route.WalkPath;
Import Com.amap.api.services.route.WalkRouteResult;
Import CN.ZMIT.XIANNENG.R;
* Created by Kyle_zheng on 2016/1/20 0020.
public class Testactivity extends activity implements Routesearch.onroutesearchlistener {
Latitude and longitude of routesearch.fromandto fromandto;//starting point and end-point
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (r.layout.test);
Mapview = (Mapview) Findviewbyid (R.ID.MAP);
Mapview.oncreate (savedinstancestate);
AMap = Mapview.getmap ();
Latlonpoint start = new Latlonpoint (31.286389, 118.378039);//starting point for the latitude and longitude of the new campus of Ann Normal University
Latlonpoint end = new Latlonpoint (31.288702, 118.360532);//The destination is the latitude and longitude of the Medical College of southern Anhui
Fromandto = new Routesearch.fromandto (start, end);//Instantiate fromandto, literally, where to
Routesearch = new Routesearch (this);//instantiated Routesearch
Routesearch.setroutesearchlistener (this);
public void DoClick (view view) {
Routesearch.busroutequery busroutequery = new Routesearch.busroutequery (fromandto, Routesearch.busdefault, "Wuhu", 0); /The first parameter represents the start and end point of the path planning, the second parameter represents the bus query mode, the third parameter indicates the bus query city area code, the fourth parameter indicates whether the night train is calculated, and 0 indicates that no calculation
Routesearch.calculatebusrouteasyn (Busroutequery);
Routesearch.driveroutequery driveroutequery = new Routesearch.driveroutequery (Fromandto, RouteSearch.DrivingDefault , NULL, NULL, "");
Routesearch.calculatedriverouteasyn (Driveroutequery);
Routesearch.walkroutequery walkroutequery = new Routesearch.walkroutequery (fromandto, RouteSearch.WalkDefault);
Routesearch.calculatewalkrouteasyn (Walkroutequery);
public void onbusroutesearched (Busrouteresult busrouteresult, int i) {
Buspath Buspath = Busrouteresult.getpaths (). get (0);//Take one of the routes
Busrouteoverlay routeoverlay = new Busrouteoverlay (this, AMap,
Buspath, Busrouteresult.getstartpos (),
Busrouteresult.gettargetpos ());
Routeoverlay.removefrommap ();
Routeoverlay.addtomap ();
Routeoverlay.zoomtospan ();
public void ondriveroutesearched (Driverouteresult driverouteresult, int i) {
Drivepath Drivepath = Driverouteresult.getpaths (). get (0);
Drivingrouteoverlay routeoverlay = new Drivingrouteoverlay (this, AMap,
Drivepath, Driverouteresult.getstartpos (),
Driverouteresult.gettargetpos ());
Routeoverlay.removefrommap ();
Routeoverlay.addtomap ();
Routeoverlay.zoomtospan ();
public void onwalkroutesearched (Walkrouteresult walkrouteresult, int i) {
Walkpath Walkpath = Walkrouteresult.getpaths (). get (0);//Take one of the routes
Amap.clear ()//clear the annotations on the map
Walkrouteoverlay routeoverlay = new Walkrouteoverlay (this, AMap,
Walkpath, Walkrouteresult.getstartpos (),
Walkrouteresult.gettargetpos ());
Routeoverlay.removefrommap ();
Routeoverlay.addtomap ();
Routeoverlay.zoomtospan ();
The following are to be carbon
protected void Onresume () {
protected void OnPause () {
protected void OnDestroy () {
Well, over, feel useful to the point of a praise it ~