Bus Routing
The bus routing is based on the coordinates of the starting point and the route of the bus travel. The sample code is as follows:
// Set the starting point and end point coordinates GeoPoint startGeoPoint = new GeoPoint(116.39750, 39.90850); //Tiananmen GeoPoint endGeoPoint = new GeoPoint(116.43423, 39.93766); //Dongzhimen Street RoutePlan routePlan = new RoutePlan(); // Set the listener routePlan.setListener(new RoutePlan.Listener() { @Override public void onSuccess(final RouteResult result) { //search successful } @Override public void onFail(final APIStatus status) { //Query failed } }); // Set the request parameters RoutePlan.Query query = RoutePlan.Query.newQuery(startGeoPoint, endGeoPoint, RoutePlanType.BUS); // Set the city query.setCity("BEIJING"); routePlan.setQuery(query); //Initiate a request routePlan.plan();
RoutePlan.Query Description:
1. Obtain an instance by using the newQuery (GeoPoint startPoint, GeoPoint endPoint, int queryType) method in RoutePlan.Query.
2. startPoint starting point GeoPoint coordinates.
3. endPoint Endpoint GeoPoint coordinates.
4. queryType calculation path type, the bus calculation path type is RoutePlanType.BUS.
5. The bus calculation method must call the setCity(String city) method to set the city, and the city is the city name keyword. For example, "Beijing City."
Note: The result return interface is an asynchronous thread interface.