Search for bus transfer routes on Baidu Map

Source: Internet
Author: User

Package com. njupt. bmap_helloworld; import com. baidu. mapapi. BMapManager; import com. baidu. mapapi. geoPoint; import com. baidu. mapapi. MKAddrInfo; import com. baidu. mapapi. MKBusLineResult; import com. baidu. mapapi. MKDrivingRouteResult; import com. baidu. mapapi. MKGeneralListener; import com. baidu. mapapi. MKPlanNode; import com. baidu. mapapi. MKPoiResult; import com. baidu. mapapi. MKSearch; import com. baidu. mapap I. MKSearchListener; import com. baidu. mapapi. MKSuggestionResult; import com. baidu. mapapi. MKTransitRouteResult; import com. baidu. mapapi. MKWalkingRouteResult; import com. baidu. mapapi. mapActivity; import com. baidu. mapapi. mapController; import com. baidu. mapapi. mapView; import com. baidu. mapapi. poiOverlay; import com. baidu. mapapi. transitOverlay; import android. OS. bundle; import android. app. activity; impo Rt android. view. menu; import android. widget. toast; public class MainActivity extends MapActivity {private MapView mapView; // controls related to Baidu map private BMapManager bMapManager; // the engine for loading maps private String keyString = "Hangzhou "; // key private MapController mapController of Baidu map; // Add some controls on Baidu map, such as the control private MKSearch mkSearch; private MKPlanNode start; private MKPlanNode end; @ Ove Rride protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); mapView = (MapView) findViewById (R. id. bmapView); bMapManager = new BMapManager (MainActivity. this); // The key bMapManager must be loaded. init (keyString, new MKGeneralListener () {@ Override public void onGetPermissionState (int arg0) {if (arg0 = 300) {Toast. makeText (MainActivity. this, "Input Incorrect key. Please verify... ", 1 ). show () ;}@ Override public void onGetNetworkState (int arg0) {// TODO Auto-generated method stub }}); initMapActivity (bMapManager); mapView. setBuiltInZoomControls (true); // you can set the zoom function mkSearch = new MKSearch (); mkSearch. init (bMapManager, new MySearchListener ();/*** initiate peripheral search based on the center point, radius, and search term * The first parameter is the query name, and the second parameter is to construct a GeoPoint, the third parameter is the query radius * // mkSearch. poiSearchNearBy ("Tsinghua University", new GeoPoi Nt (int) (39.915*1E6), (int) (116.404*1E6), 5000); start = new MKPlanNode (); start.pt = new GeoPoint (int) (39.915*1E6), (int) (116.404*1E6); end = new MKPlanNode (); end.pt = new GeoPoint (40057031,116 307852); mkSearch. transitSearch ("background", start, end);} public class MySearchListener implements MKSearchListener {@ Override public void onGetAddrResult (MKAddrInfo arg0, int arg1) {// TODO Auto-generated Method stub} @ Override public void onGetBusDetailResult (MKBusLineResult arg0, int arg1) {// TODO Auto-generated method stub} @ Override public void Merge (MKDrivingRouteResult arg0, int arg1) {// TODO Auto-generated method stub} @ Override public void onGetPoiResult (MKPoiResult result, int type, int iError) {if (result = null) {return ;} poiOverlay poiOverlay = new PoiOverla Y (MainActivity. this, mapView); poiOverlay. setData (result. getAllPoi (); // locate all the matching points in mapView. getOverlays (). add (poiOverlay); mapView. invalidate () ;}@ Override public void Merge (MKSuggestionResult arg0, int arg1) {// TODO Auto-generated method stub} @ Override public void Merge (MKTransitRouteResult arg0, int arg1) {TransitOverlay transitOverlay = new TransitOverlay (MainActivity. this, mapView); transitOverlay. setData (arg0.getPlan (0); mapView. getOverlays (). add (transitOverlay); mapView. invalidate () ;}@ Override public void onGetWalkingRouteResult (MKWalkingRouteResult arg0, int arg1) {// TODO Auto-generated method stub }@ Override protected void onDestroy () {super. onDestroy (); if (bMapManager! = Null) {bMapManager. destroy (); bMapManager = null ;}@override protected void onResume () {super. onResume (); if (bMapManager! = Null) {bMapManager. start () ;}@ Override protected void onPause () {super. onPause (); if (bMapManager! = Null) {bMapManager. stop () ;}@ Override protected boolean isRouteDisplayed () {// TODO Auto-generated method stub return false;} @ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}

 

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.